@signature-kit/clicksign 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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +313 -0
- package/package.json +53 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Initial npm-ready release for `@signature-kit/clicksign`.
|
|
6
|
+
- Published package metadata, MIT license, README, and package-local changelog.
|
|
7
|
+
- Ships alchemy v2 remote-signature provider for Clicksign document creation, lookup, cancellation, deletion, and signed-document download.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SignatureKit 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
|
+
# @signature-kit/clicksign
|
|
2
|
+
|
|
3
|
+
Alchemy v2 remote-signature provider for Clicksign document creation, lookup, cancellation, deletion, and signed-document download.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @signature-kit/clicksign effect alchemy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
- `@signature-kit/clicksign`
|
|
14
|
+
|
|
15
|
+
## Runtime model
|
|
16
|
+
|
|
17
|
+
SignatureKit packages are Effect-native. Public APIs return typed `Effect.Effect` values; recoverable faults stay in the typed error channel; callers provide required services and layers explicitly at the application boundary.
|
|
18
|
+
|
|
19
|
+
## Version
|
|
20
|
+
|
|
21
|
+
Current npm release line: `0.1.0`.
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT. See `LICENSE`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SignatureKitError } from "@signature-kit/core/config";
|
|
2
|
+
import type { RemoteSignatureRequest, RemoteSignatureRequestProps } from "@signature-kit/core/config";
|
|
3
|
+
import { SignatureHttpClient } from "@signature-kit/core/http";
|
|
4
|
+
import { Resource } from "alchemy";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
7
|
+
declare const ClicksignEnvironmentSchema: Schema.Literals<readonly ["production", "sandbox"]>;
|
|
8
|
+
export type ClicksignEnvironment = (typeof ClicksignEnvironmentSchema)["Type"];
|
|
9
|
+
declare const ClicksignLocaleSchema: Schema.Literals<readonly ["en-US", "pt-BR"]>;
|
|
10
|
+
export type ClicksignLocale = (typeof ClicksignLocaleSchema)["Type"];
|
|
11
|
+
export declare const ClicksignProviderOptionsSchema: Schema.Struct<{
|
|
12
|
+
readonly accessToken: Schema.ConstraintDecoder<Redacted.Redacted<string>, never>;
|
|
13
|
+
readonly environment: Schema.optional<Schema.Literals<readonly ["production", "sandbox"]>>;
|
|
14
|
+
readonly baseUrl: Schema.optional<Schema.NonEmptyString>;
|
|
15
|
+
readonly locale: Schema.optional<Schema.Literals<readonly ["en-US", "pt-BR"]>>;
|
|
16
|
+
readonly autoClose: Schema.optional<Schema.Boolean>;
|
|
17
|
+
}>;
|
|
18
|
+
export type ClicksignProviderOptions = (typeof ClicksignProviderOptionsSchema)["Type"];
|
|
19
|
+
export type ClicksignSignatureRequest = Resource<"SignatureKit.ClicksignSignatureRequest", RemoteSignatureRequestProps, RemoteSignatureRequest>;
|
|
20
|
+
export declare const ClicksignSignatureRequest: import("alchemy").ResourceClass<ClicksignSignatureRequest>;
|
|
21
|
+
declare const ClicksignCredentials_base: Context.ServiceClass<ClicksignCredentials, "@signature-kit/clicksign/Credentials", {
|
|
22
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
23
|
+
readonly environment?: "production" | "sandbox" | undefined;
|
|
24
|
+
readonly baseUrl?: string | undefined;
|
|
25
|
+
readonly locale?: "en-US" | "pt-BR" | undefined;
|
|
26
|
+
readonly autoClose?: boolean | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export declare class ClicksignCredentials extends ClicksignCredentials_base {
|
|
29
|
+
}
|
|
30
|
+
export declare const clicksignCredentialsLayer: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignCredentials, SignatureKitError>;
|
|
31
|
+
export declare const ClicksignSignatureRequestProvider: () => Layer.Layer<Provider.Provider<ClicksignSignatureRequest>, never, ClicksignCredentials | SignatureHttpClient>;
|
|
32
|
+
declare const ClicksignProviders_base: Provider.ProviderCollection<ClicksignProviders, "@signature-kit/clicksign/Providers">;
|
|
33
|
+
export declare class ClicksignProviders extends ClicksignProviders_base {
|
|
34
|
+
}
|
|
35
|
+
export declare const providers: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignProviders, SignatureKitError, SignatureHttpClient>;
|
|
36
|
+
export declare const getClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<RemoteSignatureRequest, SignatureKitError, SignatureHttpClient>;
|
|
37
|
+
export declare const listClicksignSignatureRequests: (options: ClicksignProviderOptions) => Effect.Effect<readonly RemoteSignatureRequest[], SignatureKitError, SignatureHttpClient>;
|
|
38
|
+
export declare const cancelClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
39
|
+
export declare const deleteClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
40
|
+
export declare const downloadClicksignSignedDocument: (options: ClicksignProviderOptions, id: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAMlB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAIV,sBAAsB,EAEtB,2BAA2B,EAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAqB,MAAM,0BAA0B,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOlE,QAAA,MAAM,0BAA0B,qDAA6C,CAAC;AAC9E,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/E,QAAA,MAAM,qBAAqB,8CAAsC,CAAC;AAClE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,eAAO,MAAM,8BAA8B;;;;;;EAMzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC;AA2KvF,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAC9C,wCAAwC,EACxC,2BAA2B,EAC3B,sBAAsB,CACvB,CAAC;AAEF,eAAO,MAAM,yBAAyB,4DAGrC,CAAC;;;;;;;;AAEF,qBAAa,oBAAqB,SAAQ,yBAGC;CAAG;AAE9C,eAAO,MAAM,yBAAyB,GACpC,SAAS,wBAAwB,KAChC,KAAK,CAAC,KAAK,CAAC,oBAAoB,EAAE,iBAAiB,CAgBnD,CAAC;AAmMJ,eAAO,MAAM,iCAAiC,oHA6B3C,CAAC;;AAEJ,qBAAa,kBAAmB,SAAQ,uBAEvC;CAAG;AAEJ,eAAO,MAAM,SAAS,GAAI,SAAS,wBAAwB,4EAIxD,CAAC;AAEJ,eAAO,MAAM,4BAA4B,GACvC,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,iBAAiB,EAAE,mBAAmB,CAiB3E,CAAC;AAEL,eAAO,MAAM,8BAA8B,GACzC,SAAS,wBAAwB,KAChC,MAAM,CAAC,MAAM,CAAC,SAAS,sBAAsB,EAAE,EAAE,iBAAiB,EAAE,mBAAmB,CAiBtF,CAAC;AAEL,eAAO,MAAM,+BAA+B,GAC1C,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,+BAA+B,GAC1C,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,+BAA+B,GAC1C,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAiB/D,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { bytesToBase64 } from "@signature-kit/crypto/base64";
|
|
2
|
+
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, SignatureKitSchemaNameValue, redactedStringSchema, remoteSignatureInputFromResourceProps, } from "@signature-kit/core/config";
|
|
3
|
+
import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/core/http";
|
|
4
|
+
import { Resource } from "alchemy";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
7
|
+
const PROVIDER = "clicksign";
|
|
8
|
+
const CLICKSIGN_PROVIDER_COLLECTION_ID = "@signature-kit/clicksign/Providers";
|
|
9
|
+
const SANDBOX_BASE_URL = "https://sandbox.clicksign.com/api/v1";
|
|
10
|
+
const PRODUCTION_BASE_URL = "https://app.clicksign.com/api/v1";
|
|
11
|
+
const ClicksignEnvironmentSchema = Schema.Literals(["production", "sandbox"]);
|
|
12
|
+
const ClicksignLocaleSchema = Schema.Literals(["en-US", "pt-BR"]);
|
|
13
|
+
export const ClicksignProviderOptionsSchema = Schema.Struct({
|
|
14
|
+
accessToken: redactedStringSchema,
|
|
15
|
+
environment: Schema.optional(ClicksignEnvironmentSchema),
|
|
16
|
+
baseUrl: Schema.optional(Schema.NonEmptyString),
|
|
17
|
+
locale: Schema.optional(ClicksignLocaleSchema),
|
|
18
|
+
autoClose: Schema.optional(Schema.Boolean),
|
|
19
|
+
});
|
|
20
|
+
const ClicksignDocumentResultSchema = Schema.Struct({
|
|
21
|
+
document: Schema.Struct({
|
|
22
|
+
key: Schema.NonEmptyString,
|
|
23
|
+
status: Schema.optional(Schema.String),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
const ClicksignSignerResultSchema = Schema.Struct({
|
|
27
|
+
signer: Schema.Struct({ key: Schema.NonEmptyString }),
|
|
28
|
+
});
|
|
29
|
+
const ClicksignListResultSchema = Schema.Struct({
|
|
30
|
+
list: Schema.Struct({ request_signature_key: Schema.NonEmptyString }),
|
|
31
|
+
});
|
|
32
|
+
const ClicksignDocumentSchema = Schema.Struct({
|
|
33
|
+
key: Schema.NonEmptyString,
|
|
34
|
+
status: Schema.optional(Schema.String),
|
|
35
|
+
download_url: Schema.optional(Schema.String),
|
|
36
|
+
downloadUrl: Schema.optional(Schema.String),
|
|
37
|
+
});
|
|
38
|
+
const ClicksignGetDocumentResponseSchema = Schema.Struct({
|
|
39
|
+
document: ClicksignDocumentSchema,
|
|
40
|
+
});
|
|
41
|
+
const ClicksignDocumentsResultSchema = Schema.Struct({
|
|
42
|
+
documents: Schema.Array(ClicksignDocumentSchema),
|
|
43
|
+
});
|
|
44
|
+
const toRemoteSignatureRequestState = (status) => {
|
|
45
|
+
if (status === undefined)
|
|
46
|
+
return "sent";
|
|
47
|
+
const normalized = status.toLowerCase();
|
|
48
|
+
if (normalized.includes("draft"))
|
|
49
|
+
return "draft";
|
|
50
|
+
if (normalized.includes("completed") || normalized.includes("signed"))
|
|
51
|
+
return "completed";
|
|
52
|
+
if (normalized.includes("cancel"))
|
|
53
|
+
return "cancelled";
|
|
54
|
+
if (normalized.includes("delete"))
|
|
55
|
+
return "deleted";
|
|
56
|
+
if (normalized.includes("declined"))
|
|
57
|
+
return "declined";
|
|
58
|
+
if (normalized.includes("expired"))
|
|
59
|
+
return "expired";
|
|
60
|
+
return "sent";
|
|
61
|
+
};
|
|
62
|
+
const toRemoteSignatureRequest = (baseUrl, document) => ({
|
|
63
|
+
provider: PROVIDER,
|
|
64
|
+
id: document.key,
|
|
65
|
+
state: toRemoteSignatureRequestState(document.status),
|
|
66
|
+
providerStatus: document.status,
|
|
67
|
+
detailsUrl: `${baseUrl}/documents/${document.key}`,
|
|
68
|
+
downloadUrl: document.download_url ??
|
|
69
|
+
document.downloadUrl ??
|
|
70
|
+
`${baseUrl}/documents/${document.key}/download`,
|
|
71
|
+
});
|
|
72
|
+
const getClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http
|
|
73
|
+
.requestJson({
|
|
74
|
+
provider: PROVIDER,
|
|
75
|
+
method: "GET",
|
|
76
|
+
...withAccessToken(baseUrl, `/documents/${id}`, options.accessToken),
|
|
77
|
+
headers: { "Content-Type": "application/json" },
|
|
78
|
+
}, ClicksignGetDocumentResponseSchema, SignatureKitSchemaNameValue.clicksignDocumentResult)
|
|
79
|
+
.pipe(Effect.map((result) => toRemoteSignatureRequest(baseUrl, result.document)));
|
|
80
|
+
const listClicksignSignatureRequestsInternal = (http, options, baseUrl) => http
|
|
81
|
+
.requestJson({
|
|
82
|
+
provider: PROVIDER,
|
|
83
|
+
method: "GET",
|
|
84
|
+
...withAccessToken(baseUrl, "/documents", options.accessToken),
|
|
85
|
+
}, ClicksignDocumentsResultSchema, SignatureKitSchemaNameValue.clicksignDocumentsResult)
|
|
86
|
+
.pipe(Effect.map((result) => result.documents.map((document) => toRemoteSignatureRequest(baseUrl, document))));
|
|
87
|
+
const cancelClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http.requestVoid({
|
|
88
|
+
provider: PROVIDER,
|
|
89
|
+
method: "POST",
|
|
90
|
+
...withAccessToken(baseUrl, `/documents/${id}/cancel`, options.accessToken),
|
|
91
|
+
});
|
|
92
|
+
const deleteClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http
|
|
93
|
+
.requestVoid({
|
|
94
|
+
provider: PROVIDER,
|
|
95
|
+
method: "DELETE",
|
|
96
|
+
...withAccessToken(baseUrl, `/documents/${id}`, options.accessToken),
|
|
97
|
+
})
|
|
98
|
+
.pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.void));
|
|
99
|
+
const downloadClicksignSignedDocumentInternal = (http, options, baseUrl, id) => getClicksignSignatureRequestInternal(http, options, baseUrl, id).pipe(Effect.flatMap((request) => {
|
|
100
|
+
const signedDocumentUrl = request.downloadUrl;
|
|
101
|
+
if (signedDocumentUrl !== undefined &&
|
|
102
|
+
(signedDocumentUrl.startsWith("http://") || signedDocumentUrl.startsWith("https://"))) {
|
|
103
|
+
return http.requestBytes({
|
|
104
|
+
provider: PROVIDER,
|
|
105
|
+
method: "GET",
|
|
106
|
+
url: signedDocumentUrl,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (signedDocumentUrl !== undefined) {
|
|
110
|
+
return http.requestBytes({
|
|
111
|
+
provider: PROVIDER,
|
|
112
|
+
method: "GET",
|
|
113
|
+
...withAccessToken(baseUrl, signedDocumentUrl.startsWith("/") ? signedDocumentUrl : `/${signedDocumentUrl}`, options.accessToken),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return http.requestBytes({
|
|
117
|
+
provider: PROVIDER,
|
|
118
|
+
method: "GET",
|
|
119
|
+
...withAccessToken(baseUrl, `/documents/${id}/download`, options.accessToken),
|
|
120
|
+
});
|
|
121
|
+
}));
|
|
122
|
+
export const ClicksignSignatureRequest = Resource("SignatureKit.ClicksignSignatureRequest", { defaultRemovalPolicy: "retain" });
|
|
123
|
+
export class ClicksignCredentials extends Context.Service()("@signature-kit/clicksign/Credentials") {
|
|
124
|
+
}
|
|
125
|
+
export const clicksignCredentialsLayer = (options) => Layer.effect(ClicksignCredentials, Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
126
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
127
|
+
retryable: false,
|
|
128
|
+
provider: PROVIDER,
|
|
129
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
130
|
+
schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
|
|
131
|
+
issueMessage: String(issue),
|
|
132
|
+
}))));
|
|
133
|
+
const clicksignBaseUrl = (options) => {
|
|
134
|
+
if (options.baseUrl !== undefined)
|
|
135
|
+
return normalizedBaseUrl(options.baseUrl);
|
|
136
|
+
if (options.environment !== undefined) {
|
|
137
|
+
return options.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL;
|
|
138
|
+
}
|
|
139
|
+
return SANDBOX_BASE_URL;
|
|
140
|
+
};
|
|
141
|
+
const withAccessToken = (baseUrl, path, token) => {
|
|
142
|
+
const url = new URL(`${baseUrl}${path}`);
|
|
143
|
+
const diagnosticUrl = new URL(`${baseUrl}${path}`);
|
|
144
|
+
url.searchParams.set("access_token", Redacted.value(token));
|
|
145
|
+
diagnosticUrl.searchParams.set("access_token", "<redacted>");
|
|
146
|
+
return { url: url.toString(), diagnosticUrl: diagnosticUrl.toString() };
|
|
147
|
+
};
|
|
148
|
+
const documentPath = (document) => document.fileName.startsWith("/") ? document.fileName : `/${document.fileName}`;
|
|
149
|
+
const recipientGroup = (recipient, index) => recipient.routingOrder ?? index + 1;
|
|
150
|
+
const createDocument = (http, options, baseUrl, input, document) => http
|
|
151
|
+
.requestJson({
|
|
152
|
+
provider: PROVIDER,
|
|
153
|
+
method: "POST",
|
|
154
|
+
...withAccessToken(baseUrl, "/documents", options.accessToken),
|
|
155
|
+
headers: { "Content-Type": "application/json" },
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
document: {
|
|
158
|
+
path: documentPath(document),
|
|
159
|
+
content_base64: `data:${document.mimeType};base64,${bytesToBase64(document.content)}`,
|
|
160
|
+
deadline_at: input.expiresAt?.toISOString(),
|
|
161
|
+
auto_close: options.autoClose ?? true,
|
|
162
|
+
locale: options.locale ?? "pt-BR",
|
|
163
|
+
sequence_enabled: input.recipients.length > 1 ||
|
|
164
|
+
input.recipients.some((recipient) => recipient.routingOrder !== undefined),
|
|
165
|
+
},
|
|
166
|
+
}),
|
|
167
|
+
}, ClicksignDocumentResultSchema, SignatureKitSchemaNameValue.clicksignDocumentResult)
|
|
168
|
+
.pipe(Effect.map((result) => result.document.key));
|
|
169
|
+
const createSigner = (http, options, baseUrl, recipient) => http
|
|
170
|
+
.requestJson({
|
|
171
|
+
provider: PROVIDER,
|
|
172
|
+
method: "POST",
|
|
173
|
+
...withAccessToken(baseUrl, "/signers", options.accessToken),
|
|
174
|
+
headers: { "Content-Type": "application/json" },
|
|
175
|
+
body: JSON.stringify({
|
|
176
|
+
signer: {
|
|
177
|
+
email: recipient.email,
|
|
178
|
+
name: recipient.name,
|
|
179
|
+
auths: ["email"],
|
|
180
|
+
has_documentation: false,
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
}, ClicksignSignerResultSchema, SignatureKitSchemaNameValue.clicksignSignerResult)
|
|
184
|
+
.pipe(Effect.map((result) => result.signer.key));
|
|
185
|
+
const linkRecipient = (http, options, baseUrl, documentKey, signerKey, recipient, index, message) => http
|
|
186
|
+
.requestJson({
|
|
187
|
+
provider: PROVIDER,
|
|
188
|
+
method: "POST",
|
|
189
|
+
...withAccessToken(baseUrl, "/lists", options.accessToken),
|
|
190
|
+
headers: { "Content-Type": "application/json" },
|
|
191
|
+
body: JSON.stringify({
|
|
192
|
+
list: {
|
|
193
|
+
document_key: documentKey,
|
|
194
|
+
signer_key: signerKey,
|
|
195
|
+
sign_as: recipient.role === "approver" ? "approve" : "sign",
|
|
196
|
+
group: recipientGroup(recipient, index),
|
|
197
|
+
message,
|
|
198
|
+
},
|
|
199
|
+
}),
|
|
200
|
+
}, ClicksignListResultSchema, SignatureKitSchemaNameValue.clicksignListResult)
|
|
201
|
+
.pipe(Effect.map((result) => result.list.request_signature_key));
|
|
202
|
+
const notifyRecipient = (http, options, baseUrl, requestSignatureKey, input) => http.requestVoid({
|
|
203
|
+
provider: PROVIDER,
|
|
204
|
+
method: "POST",
|
|
205
|
+
...withAccessToken(baseUrl, "/notifications", options.accessToken),
|
|
206
|
+
headers: { "Content-Type": "application/json" },
|
|
207
|
+
body: JSON.stringify({
|
|
208
|
+
request_signature_key: requestSignatureKey,
|
|
209
|
+
message: input.message,
|
|
210
|
+
url: input.redirectUrl,
|
|
211
|
+
}),
|
|
212
|
+
});
|
|
213
|
+
const createRemoteRequest = (http, options, baseUrl, input) => {
|
|
214
|
+
const document = input.documents[0];
|
|
215
|
+
if (input.documents.length !== 1 || document === undefined) {
|
|
216
|
+
return Effect.fail(new SignatureKitError({
|
|
217
|
+
code: SignatureKitErrorCodeValue.unsupportedOperation,
|
|
218
|
+
retryable: false,
|
|
219
|
+
provider: PROVIDER,
|
|
220
|
+
operation: SignatureKitOperationValue.remoteCreate,
|
|
221
|
+
reason: "Clicksign API v1 supports one uploaded document per signature request.",
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
return createDocument(http, options, baseUrl, input, document).pipe(Effect.map((documentKey) => ({ documentKey })), Effect.flatMap(({ documentKey }) => Effect.forEach(input.recipients, (recipient, index) => createSigner(http, options, baseUrl, recipient).pipe(Effect.flatMap((signerKey) => linkRecipient(http, options, baseUrl, documentKey, signerKey, recipient, index, input.message)))).pipe(Effect.map((requestSignatureKeys) => ({ documentKey, requestSignatureKeys })))), Effect.flatMap(({ documentKey, requestSignatureKeys }) => input.send === false
|
|
225
|
+
? Effect.succeed({ documentKey })
|
|
226
|
+
: Effect.forEach(requestSignatureKeys, (requestSignatureKey) => notifyRecipient(http, options, baseUrl, requestSignatureKey, input), { discard: true }).pipe(Effect.as({ documentKey }))), Effect.map(({ documentKey }) => ({
|
|
227
|
+
provider: PROVIDER,
|
|
228
|
+
id: documentKey,
|
|
229
|
+
state: input.send === false ? "draft" : "sent",
|
|
230
|
+
})));
|
|
231
|
+
};
|
|
232
|
+
export const ClicksignSignatureRequestProvider = () => Provider.effect(ClicksignSignatureRequest, Effect.gen(function* () {
|
|
233
|
+
const options = yield* ClicksignCredentials;
|
|
234
|
+
const http = yield* SignatureHttpClient;
|
|
235
|
+
const baseUrl = clicksignBaseUrl(options);
|
|
236
|
+
return ClicksignSignatureRequest.Provider.of({
|
|
237
|
+
diff: ({ olds }) => Effect.succeed(olds === undefined ? undefined : { action: "noop" }),
|
|
238
|
+
list: () => listClicksignSignatureRequestsInternal(http, options, baseUrl),
|
|
239
|
+
read: ({ output }) => output === undefined
|
|
240
|
+
? Effect.succeed(undefined)
|
|
241
|
+
: getClicksignSignatureRequestInternal(http, options, baseUrl, output.id).pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined))),
|
|
242
|
+
reconcile: Effect.fn(function* ({ news, output }) {
|
|
243
|
+
if (output !== undefined)
|
|
244
|
+
return output;
|
|
245
|
+
const input = yield* remoteSignatureInputFromResourceProps(PROVIDER, news);
|
|
246
|
+
return yield* createRemoteRequest(http, options, baseUrl, input);
|
|
247
|
+
}),
|
|
248
|
+
delete: ({ output }) => deleteClicksignSignatureRequestInternal(http, options, baseUrl, output.id),
|
|
249
|
+
});
|
|
250
|
+
}));
|
|
251
|
+
export class ClicksignProviders extends Provider.ProviderCollection()(CLICKSIGN_PROVIDER_COLLECTION_ID) {
|
|
252
|
+
}
|
|
253
|
+
export const providers = (options) => Layer.effect(ClicksignProviders, Provider.collection([ClicksignSignatureRequest])).pipe(Layer.provide(ClicksignSignatureRequestProvider()), Layer.provide(clicksignCredentialsLayer(options)));
|
|
254
|
+
export const getClicksignSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
255
|
+
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
256
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
257
|
+
retryable: false,
|
|
258
|
+
provider: PROVIDER,
|
|
259
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
260
|
+
schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
|
|
261
|
+
issueMessage: String(issue),
|
|
262
|
+
})));
|
|
263
|
+
const http = yield* SignatureHttpClient;
|
|
264
|
+
return yield* getClicksignSignatureRequestInternal(http, valid, clicksignBaseUrl(valid), id);
|
|
265
|
+
});
|
|
266
|
+
export const listClicksignSignatureRequests = (options) => Effect.gen(function* () {
|
|
267
|
+
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
268
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
269
|
+
retryable: false,
|
|
270
|
+
provider: PROVIDER,
|
|
271
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
272
|
+
schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
|
|
273
|
+
issueMessage: String(issue),
|
|
274
|
+
})));
|
|
275
|
+
const http = yield* SignatureHttpClient;
|
|
276
|
+
return yield* listClicksignSignatureRequestsInternal(http, valid, clicksignBaseUrl(valid));
|
|
277
|
+
});
|
|
278
|
+
export const cancelClicksignSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
279
|
+
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
280
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
281
|
+
retryable: false,
|
|
282
|
+
provider: PROVIDER,
|
|
283
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
284
|
+
schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
|
|
285
|
+
issueMessage: String(issue),
|
|
286
|
+
})));
|
|
287
|
+
const http = yield* SignatureHttpClient;
|
|
288
|
+
return yield* cancelClicksignSignatureRequestInternal(http, valid, clicksignBaseUrl(valid), id);
|
|
289
|
+
});
|
|
290
|
+
export const deleteClicksignSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
291
|
+
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
292
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
293
|
+
retryable: false,
|
|
294
|
+
provider: PROVIDER,
|
|
295
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
296
|
+
schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
|
|
297
|
+
issueMessage: String(issue),
|
|
298
|
+
})));
|
|
299
|
+
const http = yield* SignatureHttpClient;
|
|
300
|
+
return yield* deleteClicksignSignatureRequestInternal(http, valid, clicksignBaseUrl(valid), id);
|
|
301
|
+
});
|
|
302
|
+
export const downloadClicksignSignedDocument = (options, id) => Effect.gen(function* () {
|
|
303
|
+
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
304
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
305
|
+
retryable: false,
|
|
306
|
+
provider: PROVIDER,
|
|
307
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
308
|
+
schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
|
|
309
|
+
issueMessage: String(issue),
|
|
310
|
+
})));
|
|
311
|
+
const http = yield* SignatureHttpClient;
|
|
312
|
+
return yield* downloadClicksignSignedDocumentInternal(http, valid, clicksignBaseUrl(valid), id);
|
|
313
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signature-kit/clicksign",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"CHANGELOG.md"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -b tsconfig.json",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"test": "vitest run"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@signature-kit/core": "^0.1.0",
|
|
31
|
+
"@signature-kit/crypto": "^0.1.0",
|
|
32
|
+
"alchemy": "2.0.0-beta.57",
|
|
33
|
+
"effect": "4.0.0-beta.86"
|
|
34
|
+
},
|
|
35
|
+
"nx": {
|
|
36
|
+
"targets": {
|
|
37
|
+
"npm-pack": {
|
|
38
|
+
"executor": "nx:run-commands",
|
|
39
|
+
"options": {
|
|
40
|
+
"command": "npm pack --dry-run --json",
|
|
41
|
+
"cwd": "{projectRoot}"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"npm-publish": {
|
|
45
|
+
"executor": "nx:run-commands",
|
|
46
|
+
"options": {
|
|
47
|
+
"command": "npm publish --access public",
|
|
48
|
+
"cwd": "{projectRoot}"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|