@bhanquier/template-sdk 0.1.2
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/index.cjs +71 -0
- package/dist/index.js +46 -0
- package/package.json +43 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
TemplateSdkClient: () => TemplateSdkClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var TemplateSdkClient = class {
|
|
27
|
+
baseUrl;
|
|
28
|
+
apiKey;
|
|
29
|
+
fetchImpl;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
32
|
+
this.apiKey = options.apiKey;
|
|
33
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
34
|
+
}
|
|
35
|
+
async analyze(payload) {
|
|
36
|
+
return this.postJson("/v1/templates/analyze", payload);
|
|
37
|
+
}
|
|
38
|
+
async render(payload) {
|
|
39
|
+
return this.postJson("/v1/templates/render", payload);
|
|
40
|
+
}
|
|
41
|
+
async renderDocx(payload, responseMode = "json") {
|
|
42
|
+
return this.postJson("/v1/templates/render", {
|
|
43
|
+
mode: "docx",
|
|
44
|
+
responseMode,
|
|
45
|
+
payload
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async renderForm(payload, responseMode = "json") {
|
|
49
|
+
return this.postJson("/v1/templates/render", {
|
|
50
|
+
mode: "form",
|
|
51
|
+
responseMode,
|
|
52
|
+
payload
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async postJson(path, payload) {
|
|
56
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: {
|
|
59
|
+
"Content-Type": "application/json",
|
|
60
|
+
...this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify(payload)
|
|
63
|
+
});
|
|
64
|
+
const body = await response.json();
|
|
65
|
+
return body;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
TemplateSdkClient
|
|
71
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var TemplateSdkClient = class {
|
|
3
|
+
baseUrl;
|
|
4
|
+
apiKey;
|
|
5
|
+
fetchImpl;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
8
|
+
this.apiKey = options.apiKey;
|
|
9
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
10
|
+
}
|
|
11
|
+
async analyze(payload) {
|
|
12
|
+
return this.postJson("/v1/templates/analyze", payload);
|
|
13
|
+
}
|
|
14
|
+
async render(payload) {
|
|
15
|
+
return this.postJson("/v1/templates/render", payload);
|
|
16
|
+
}
|
|
17
|
+
async renderDocx(payload, responseMode = "json") {
|
|
18
|
+
return this.postJson("/v1/templates/render", {
|
|
19
|
+
mode: "docx",
|
|
20
|
+
responseMode,
|
|
21
|
+
payload
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async renderForm(payload, responseMode = "json") {
|
|
25
|
+
return this.postJson("/v1/templates/render", {
|
|
26
|
+
mode: "form",
|
|
27
|
+
responseMode,
|
|
28
|
+
payload
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async postJson(path, payload) {
|
|
32
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
...this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify(payload)
|
|
39
|
+
});
|
|
40
|
+
const body = await response.json();
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
TemplateSdkClient
|
|
46
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bhanquier/template-sdk",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "HTTP SDK for template-service APIs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/TrustAkt/trustakt-templating.git"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@bhanquier/template-core": "0.1.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.10.0",
|
|
32
|
+
"tsup": "^8.5.1",
|
|
33
|
+
"typescript": "^5.3.0",
|
|
34
|
+
"vitest": "^4.0.15"
|
|
35
|
+
},
|
|
36
|
+
"license": "UNLICENSED",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup src/index.ts --format esm,cjs --out-dir dist --clean && tsc --noEmit",
|
|
39
|
+
"dev": "tsup src/index.ts --format esm,cjs --out-dir dist --watch",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
42
|
+
}
|
|
43
|
+
}
|