@uveysservetoglu/kobil-sign 1.0.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/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @uveysservetoglu/kobil-sign
2
+
3
+ KOBIL digital signature client for Node.js / TypeScript, with automatic OAuth token management.
4
+
5
+ ```bash
6
+ npm install @uveysservetoglu/kobil-sign
7
+ ```
8
+
9
+ ```ts
10
+ import { SignClient } from "@uveysservetoglu/kobil-sign";
11
+
12
+ const sign = new SignClient({
13
+ // credentials (or KOBIL_* env vars):
14
+ tokenEndpoint: process.env.KOBIL_TOKEN_ENDPOINT!,
15
+ clientId: process.env.KOBIL_CLIENT_ID!,
16
+ clientSecret: process.env.KOBIL_CLIENT_SECRET!,
17
+ // sign-specific:
18
+ signBaseUrl: "https://idp.cloud.kobil.com/auth/realms/{TENANT}/mpower/v1/users/{USER_ID}",
19
+ tenantName: "acme",
20
+ defaultCallbackUrl: "https://yourapi.com/signature-callback",
21
+ });
22
+
23
+ const res = await sign.initiatePdfSignature({
24
+ userId,
25
+ file: pdfBytes,
26
+ fileName: "Agreement.pdf",
27
+ messageText: "Please sign here",
28
+ position: { pageNumber: 1, bottomLeftX: 59, bottomLeftY: 89, topRightX: 85, topRightY: 96 },
29
+ });
30
+ // res.messageId, res.instanceId
31
+ ```
32
+
33
+ `{TENANT}` is filled from `tenantName`, `{USER_ID}` from the call; `/signature` is appended.
34
+
35
+ ### How it maps to the API
36
+
37
+ `POST {signBaseUrl}/signature` as `multipart/form-data`:
38
+
39
+ - `signatureFile` — the PDF bytes (`application/pdf`)
40
+ - `signatureData` — JSON: `version`, `pageNumber`, `bottomLeft*/topRight*Coordinate`,
41
+ `serviceUuid`, `messageText`, `callbackUrl`
42
+
43
+ The signed PDF is delivered to your callback as a `signatureResponse`; download it by its
44
+ `mediaId` using `@uveysservetoglu/kobil-chat`'s `getAttachmentFile`.
45
+
46
+ JavaScript usage is identical (`const { SignClient } = require("@uveysservetoglu/kobil-sign")`).
47
+ Failures throw `KobilSignError` (extends `KobilError`).
48
+
49
+ ## License
50
+
51
+ MIT
@@ -0,0 +1,30 @@
1
+ import { KobilCredentials, KobilError, KobilServiceClient, TokenProvider } from "@uveysservetoglu/kobil-core";
2
+ import { InitiateSignatureInput, SignatureResult } from "./types";
3
+ export interface SignClientOptions extends Partial<KobilCredentials> {
4
+ /** Signature endpoint template up to the user segment, with {TENANT} and {USER_ID}. */
5
+ signBaseUrl: string;
6
+ /** Tenant/realm name substituted for {TENANT}. */
7
+ tenantName?: string;
8
+ /** serviceUuid sent with the request. Optional: defaults to clientId. */
9
+ serviceUuid?: string;
10
+ /** Default callback URL for signature results; overridable per request. */
11
+ defaultCallbackUrl?: string;
12
+ /** Wire protocol version. Default: 3. */
13
+ version?: number;
14
+ tokenProvider?: TokenProvider;
15
+ }
16
+ /** Client for the KOBIL digital signature API. */
17
+ export declare class SignClient extends KobilServiceClient {
18
+ private readonly signBaseUrl;
19
+ private readonly tenantName?;
20
+ private readonly clientId;
21
+ private readonly serviceUuidOption?;
22
+ private readonly defaultCallbackUrl?;
23
+ private readonly version;
24
+ constructor(options: SignClientOptions);
25
+ protected makeError(message: string, statusCode?: number, responseBody?: string, cause?: unknown): KobilError;
26
+ initiatePdfSignature(input: InitiateSignatureInput, signal?: AbortSignal): Promise<SignatureResult>;
27
+ private signatureUrl;
28
+ private serviceUuid;
29
+ }
30
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,aAAa,EAEd,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAElE,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAClE,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,kDAAkD;AAClD,qBAAa,UAAW,SAAQ,kBAAkB;IAChD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,iBAAiB;cAqBnB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,UAAU;IAItH,oBAAoB,CAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IAwBnG,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,WAAW;CAGpB"}
package/dist/client.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignClient = void 0;
4
+ const kobil_core_1 = require("@uveysservetoglu/kobil-core");
5
+ const error_1 = require("./error");
6
+ /** Client for the KOBIL digital signature API. */
7
+ class SignClient extends kobil_core_1.KobilServiceClient {
8
+ signBaseUrl;
9
+ tenantName;
10
+ clientId;
11
+ serviceUuidOption;
12
+ defaultCallbackUrl;
13
+ version;
14
+ constructor(options) {
15
+ const credentials = (0, kobil_core_1.credentialsFromEnv)({
16
+ tokenEndpoint: options.tokenEndpoint,
17
+ clientId: options.clientId,
18
+ clientSecret: options.clientSecret,
19
+ tokenAuthMode: options.tokenAuthMode,
20
+ defaultTokenTtlSeconds: options.defaultTokenTtlSeconds,
21
+ tokenExpirySkewSeconds: options.tokenExpirySkewSeconds,
22
+ });
23
+ super(options.tokenProvider ?? new kobil_core_1.DefaultTokenProvider(credentials));
24
+ if (!options.signBaseUrl)
25
+ throw new kobil_core_1.KobilError("signBaseUrl is required.");
26
+ this.signBaseUrl = options.signBaseUrl;
27
+ this.tenantName = options.tenantName;
28
+ this.clientId = credentials.clientId;
29
+ this.serviceUuidOption = options.serviceUuid;
30
+ this.defaultCallbackUrl = options.defaultCallbackUrl;
31
+ this.version = options.version ?? 3;
32
+ }
33
+ makeError(message, statusCode, responseBody, cause) {
34
+ return new error_1.KobilSignError(message, { statusCode, responseBody, cause });
35
+ }
36
+ initiatePdfSignature(input, signal) {
37
+ if (!input.userId)
38
+ throw new error_1.KobilSignError("userId cannot be empty.");
39
+ if (!input.file || input.file.length === 0)
40
+ throw new error_1.KobilSignError("file (PDF) cannot be empty.");
41
+ const p = input.position;
42
+ const signatureData = {
43
+ version: this.version,
44
+ pageNumber: p.pageNumber ?? 1,
45
+ bottomLeftXCoordinate: p.bottomLeftX,
46
+ bottomLeftYCoordinate: p.bottomLeftY,
47
+ topRightXCoordinate: p.topRightX,
48
+ topRightYCoordinate: p.topRightY,
49
+ serviceUuid: this.serviceUuid(),
50
+ messageText: input.messageText,
51
+ callbackUrl: input.callbackUrl ?? this.defaultCallbackUrl,
52
+ };
53
+ const form = new FormData();
54
+ form.append("signatureFile", new Blob([input.file], { type: "application/pdf" }), input.fileName ?? "document.pdf");
55
+ form.append("signatureData", JSON.stringify(signatureData));
56
+ return this.send("POST", this.signatureUrl(input.userId), form, signal);
57
+ }
58
+ signatureUrl(userId) {
59
+ const base = replaceTokens(this.signBaseUrl, { "{TENANT}": this.tenantName, "{USER_ID}": userId }).replace(/\/+$/, "");
60
+ return `${base}/signature`;
61
+ }
62
+ serviceUuid() {
63
+ return this.serviceUuidOption && this.serviceUuidOption.length > 0 ? this.serviceUuidOption : this.clientId;
64
+ }
65
+ }
66
+ exports.SignClient = SignClient;
67
+ function replaceTokens(template, tokens) {
68
+ let result = template;
69
+ for (const [token, value] of Object.entries(tokens)) {
70
+ result = result.split(token).join(encodeURIComponent(value ?? ""));
71
+ }
72
+ return result;
73
+ }
74
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,4DAOqC;AACrC,mCAAyC;AAiBzC,kDAAkD;AAClD,MAAa,UAAW,SAAQ,+BAAkB;IAC/B,WAAW,CAAS;IACpB,UAAU,CAAU;IACpB,QAAQ,CAAS;IACjB,iBAAiB,CAAU;IAC3B,kBAAkB,CAAU;IAC5B,OAAO,CAAS;IAEjC,YAAY,OAA0B;QACpC,MAAM,WAAW,GAAG,IAAA,+BAAkB,EAAC;YACrC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;YACtD,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;SACvD,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,IAAI,iCAAoB,CAAC,WAAW,CAAC,CAAC,CAAC;QAEtE,IAAI,CAAC,OAAO,CAAC,WAAW;YAAE,MAAM,IAAI,uBAAU,CAAC,0BAA0B,CAAC,CAAC;QAE3E,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAA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0,0 +1,5 @@
1
+ import { KobilError } from "@uveysservetoglu/kobil-core";
2
+ /** Thrown when a signature operation fails. */
3
+ export declare class KobilSignError extends KobilError {
4
+ }
5
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,+CAA+C;AAC/C,qBAAa,cAAe,SAAQ,UAAU;CAAG"}
package/dist/error.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KobilSignError = void 0;
4
+ const kobil_core_1 = require("@uveysservetoglu/kobil-core");
5
+ /** Thrown when a signature operation fails. */
6
+ class KobilSignError extends kobil_core_1.KobilError {
7
+ }
8
+ exports.KobilSignError = KobilSignError;
9
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AAEzD,+CAA+C;AAC/C,MAAa,cAAe,SAAQ,uBAAU;CAAG;AAAjD,wCAAiD"}
@@ -0,0 +1,5 @@
1
+ export { SignClient } from "./client";
2
+ export type { SignClientOptions } from "./client";
3
+ export { KobilSignError } from "./error";
4
+ export type { InitiateSignatureInput, SignaturePosition, SignatureResult } from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KobilSignError = exports.SignClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "SignClient", { enumerable: true, get: function () { return client_1.SignClient; } });
6
+ var error_1 = require("./error");
7
+ Object.defineProperty(exports, "KobilSignError", { enumerable: true, get: function () { return error_1.KobilSignError; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AAEnB,iCAAyC;AAAhC,uGAAA,cAAc,OAAA"}
@@ -0,0 +1,27 @@
1
+ /** Rectangle (in PDF points) where the signature is placed on a page. */
2
+ export interface SignaturePosition {
3
+ /** 1-based page number. Default: 1. */
4
+ pageNumber?: number;
5
+ bottomLeftX: number;
6
+ bottomLeftY: number;
7
+ topRightX: number;
8
+ topRightY: number;
9
+ }
10
+ export interface InitiateSignatureInput {
11
+ userId: string;
12
+ /** Raw PDF bytes to be signed. */
13
+ file: Uint8Array;
14
+ /** File name for the upload part. Default: "document.pdf". */
15
+ fileName?: string;
16
+ /** Prompt shown to the signer. */
17
+ messageText?: string;
18
+ /** Callback URL for the signature result. Falls back to the configured default. */
19
+ callbackUrl?: string;
20
+ position: SignaturePosition;
21
+ }
22
+ export interface SignatureResult {
23
+ messageId?: string;
24
+ instanceId?: string;
25
+ [key: string]: unknown;
26
+ }
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@uveysservetoglu/kobil-sign",
3
+ "version": "1.0.0",
4
+ "description": "KOBIL digital signature client for Node.js: initiate PDF signatures with automatic OAuth token management.",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "keywords": [
12
+ "kobil",
13
+ "signature",
14
+ "pdf",
15
+ "esign"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/uveysservetoglu/kobil-sdks"
20
+ },
21
+ "dependencies": {
22
+ "@uveysservetoglu/kobil-core": "^1.0.0"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc -b"
26
+ }
27
+ }