@signature-kit/clicksign 0.2.0 → 0.4.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 +47 -1
- package/README.md +90 -8
- package/dist/index.d.ts +95 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +217 -115
- package/package.json +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
|
+
## @signature-kit/clicksign@0.4.0
|
|
2
|
+
|
|
3
|
+
### Runtime updates and signature inspection
|
|
4
|
+
|
|
5
|
+
Update to stable Effect 4 and current compatible dependencies. Error classes use the native branded Schema.TaggedError constructor. Use TypeScript 7 for builds and checks with the official TypeScript 6 API compatibility alias. Upgrade direct ASN.1 dependencies to v4, interchange SDK values through DER, and encode timestamp requests with the native RFC 3161 schema. Packages do not require a consumer ASN.1 override.
|
|
6
|
+
|
|
7
|
+
Add per-signature PDF verification, certificate-validity inspection through the Effect clock, and cancellable polling for final request states in all five remote signers. Applications control polling deadlines and retry policy; a terminal request is not necessarily completed.
|
|
8
|
+
|
|
9
|
+
Update the documentation runtime, use the loading task for PDF.js cleanup, and fix dynamic Node routes by forwarding Request.duplex in the Hono adapter. Keep the app and Fumapress on a single Waku runtime.
|
|
10
|
+
|
|
11
|
+
Reject non-finite domain numbers, validate XML signature methods before WebCrypto verification, and preserve unexpected SDK failures as defects. Strengthen native Effect and accessibility lint checks.
|
|
12
|
+
|
|
13
|
+
Add branded PDF stamps with proportional PNG logos and handwriting, theme/title controls, and a PDF-rendered preview. Run browser PDF preparation and preview rendering through native Effect worker RPC with scoped termination and typed validation failures. Preserve caller buffers and signing dates across the worker boundary.
|
|
14
|
+
|
|
15
|
+
Fix structured batch stamp option conflicts, reject badges without usable drawing space, and prevent premeasured text from wrapping into adjacent rows. Restore signer interaction after React StrictMode mount replay and register localized Fumapress demo routes through the framework's native locale option. Add real worker, StrictMode, PDF text-stream, cropped/rotated page, cancellation, and invalid-image regressions.
|
|
16
|
+
|
|
1
17
|
# Changelog
|
|
2
18
|
|
|
19
|
+
## Unreleased
|
|
20
|
+
|
|
21
|
+
- Keep concrete credentials, provider, and provider-collection wiring private; consumers compose `ClicksignSignatureRequest` through `providers(options)`.
|
|
22
|
+
|
|
23
|
+
## 0.3.0
|
|
24
|
+
|
|
25
|
+
- Clicksign now owns its document/signature-request props, attributes, state
|
|
26
|
+
schema, schema names, and retained no-op diff instead of using core
|
|
27
|
+
remote-signature contracts.
|
|
28
|
+
- Decode provider options through a cached credential Effect, so retained-resource
|
|
29
|
+
`list` hooks and `read` calls without cached output do not touch credentials.
|
|
30
|
+
- Cancel Clicksign documents with `PATCH /api/v1/documents/{key}/cancel`, matching
|
|
31
|
+
the provider API that rejected the previous `POST`.
|
|
32
|
+
- Stop fabricating signed-document download URLs; absent signed-file URLs now stay
|
|
33
|
+
absent and download attempts fail as typed `unsupportedOperation` errors.
|
|
34
|
+
- Enable sequential signing only when at least one signer has `routingOrder`, so
|
|
35
|
+
unordered multi-signer requests remain parallel.
|
|
36
|
+
- Redact `access_token` from token-bearing signed-document diagnostic URLs, so
|
|
37
|
+
typed error reasons never leak provider download secrets.
|
|
38
|
+
- Limit create rollback deletion to unambiguous pre-effect 4xx failures (except
|
|
39
|
+
408, 409, and 429); response-shape errors, 5xxs, and timeouts no longer delete
|
|
40
|
+
possibly live documents.
|
|
41
|
+
- Add offline local-HTTP-server coverage for Clicksign provider behavior in the
|
|
42
|
+
default test suite.
|
|
43
|
+
|
|
44
|
+
Breaking: request props now use `ClicksignSignatureRequestProps` with
|
|
45
|
+
`contentBase64` documents, and `getClicksignSignatureRequest` /
|
|
46
|
+
`listClicksignSignatureRequests` return `ClicksignSignatureRequestAttributes`
|
|
47
|
+
instead of core `RemoteSignature*` types.
|
|
48
|
+
|
|
3
49
|
## 0.2.0
|
|
4
50
|
|
|
5
51
|
- Authenticate same-host signed-document downloads (previously the fallback URL was requested
|
|
@@ -13,4 +59,4 @@
|
|
|
13
59
|
|
|
14
60
|
- Initial npm-ready release for `@signature-kit/clicksign`.
|
|
15
61
|
- Published package metadata, MIT license, README, and package-local changelog.
|
|
16
|
-
- Ships
|
|
62
|
+
- Ships an Alchemy v2 remote-signature provider for Clicksign document creation, lookup, cancellation, deletion, and signed-document download.
|
package/README.md
CHANGED
|
@@ -1,24 +1,106 @@
|
|
|
1
1
|
# @signature-kit/clicksign
|
|
2
2
|
|
|
3
|
-
Alchemy v2 remote-signature provider for Clicksign document creation, lookup, cancellation, deletion, and signed-
|
|
3
|
+
Alchemy v2 remote-signature provider for Clicksign document creation, lookup, listing, cancellation, deletion, and signed-file download.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
bun add @signature-kit/clicksign effect alchemy
|
|
8
|
+
bun add @signature-kit/clicksign @signature-kit/http effect alchemy
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
`effect` and `alchemy` are direct runtime dependencies. Provide
|
|
12
|
+
`signatureHttpClientLive` at the stack boundary; `providers(options)` supplies
|
|
13
|
+
only Clicksign credentials and resource providers. Provider options are stored as
|
|
14
|
+
a cached credential Effect, so retained `list` hooks and `read` calls without
|
|
15
|
+
cached output do not decode credentials.
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
## Public surface
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
- `@signature-kit/clicksign` — Clicksign request/document/signer schemas, `ClicksignSignatureRequest`, `providers`, `getClicksignSignatureRequest`, `listClicksignSignatureRequests`, `cancelClicksignSignatureRequest`, `deleteClicksignSignatureRequest`, and `downloadClicksignSignedDocument`.
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
Capability matrix:
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
| Capability | Supported |
|
|
24
|
+
| ------------------------------- | -------------------------------------------------- |
|
|
25
|
+
| Create retained Alchemy request | Yes |
|
|
26
|
+
| Get request | Yes |
|
|
27
|
+
| List requests | Yes |
|
|
28
|
+
| Cancel request | Yes, via `PATCH /documents/{key}/cancel` |
|
|
29
|
+
| Delete request | Yes |
|
|
30
|
+
| Download signed document | Yes, only when Clicksign exposes a signed-file URL |
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
Retained-resource semantics: Alchemy `reconcile` creates once and returns cached output on subsequent plans; provider `list` returns `[]`; `nuke` is skipped. Multi-step create rollback deletes remote state only after unambiguous pre-effect 4xx failures, excluding 408, 409, 429, 5xx, timeouts, and response-shape failures.
|
|
33
|
+
|
|
34
|
+
## Example
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import * as Alchemy from "alchemy";
|
|
38
|
+
import {
|
|
39
|
+
ClicksignSignatureRequest,
|
|
40
|
+
cancelClicksignSignatureRequest,
|
|
41
|
+
providers as clicksignProviders,
|
|
42
|
+
type ClicksignProviderOptions,
|
|
43
|
+
} from "@signature-kit/clicksign";
|
|
44
|
+
import { signatureHttpClientLive } from "@signature-kit/http";
|
|
45
|
+
import { Effect, Layer, Redacted } from "effect";
|
|
46
|
+
|
|
47
|
+
declare const pdfBase64: string;
|
|
48
|
+
declare const accessToken: string;
|
|
49
|
+
|
|
50
|
+
const options: ClicksignProviderOptions = {
|
|
51
|
+
accessToken: Redacted.make(accessToken),
|
|
52
|
+
environment: "sandbox",
|
|
53
|
+
locale: "pt-BR",
|
|
54
|
+
autoClose: true,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default class Contracts extends Alchemy.Stack<Contracts>()(
|
|
58
|
+
"Contracts",
|
|
59
|
+
{
|
|
60
|
+
providers: Layer.merge(clicksignProviders(options), signatureHttpClientLive),
|
|
61
|
+
state: Alchemy.inMemoryState(),
|
|
62
|
+
},
|
|
63
|
+
Effect.gen(function* () {
|
|
64
|
+
return yield* ClicksignSignatureRequest("service-agreement", {
|
|
65
|
+
title: "Service agreement",
|
|
66
|
+
message: "Review and sign this document.",
|
|
67
|
+
documents: [
|
|
68
|
+
{ fileName: "contract.pdf", mimeType: "application/pdf", contentBase64: pdfBase64 },
|
|
69
|
+
],
|
|
70
|
+
recipients: [{ name: "Ada Lovelace", email: "ada@example.com", role: "signer" }],
|
|
71
|
+
send: true,
|
|
72
|
+
});
|
|
73
|
+
}),
|
|
74
|
+
) {}
|
|
75
|
+
|
|
76
|
+
export const cancelRequest = (id: string) =>
|
|
77
|
+
cancelClicksignSignatureRequest(options, id).pipe(Effect.provide(signatureHttpClientLive));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Wait for a final state
|
|
81
|
+
|
|
82
|
+
`waitForClicksignSignatureRequest(options, id, pollInterval)` reads immediately and polls while the request is `draft` or `sent`. It returns the provider's final state, including cancellation, rejection, deletion, or expiry; inspect `state` before downloading. The interval must be positive and finite. Read failures propagate immediately without automatic retry. Interruption cancels the active read and stops future polls. The caller owns the deadline:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { waitForClicksignSignatureRequest } from "@signature-kit/clicksign";
|
|
86
|
+
import { signatureHttpClientLive } from "@signature-kit/http";
|
|
87
|
+
import { Duration, Effect } from "effect";
|
|
88
|
+
import type { ClicksignProviderOptions } from "@signature-kit/clicksign";
|
|
89
|
+
|
|
90
|
+
declare const options: ClicksignProviderOptions;
|
|
91
|
+
declare const requestId: string;
|
|
92
|
+
|
|
93
|
+
const program = waitForClicksignSignatureRequest(options, requestId, Duration.seconds(2)).pipe(
|
|
94
|
+
Effect.timeout(Duration.minutes(5)),
|
|
95
|
+
Effect.provide(signatureHttpClientLive),
|
|
96
|
+
);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Errors and i18n
|
|
100
|
+
|
|
101
|
+
Invalid inputs, remote HTTP failures, unsupported operations, and invalid response shapes fail as `SignatureKitError` from `@signature-kit/signatures`. Applications can render localized copy through `errorMessage` from `@signature-kit/i18n` with the `signatureKitErrorMessages` catalog from `@signature-kit/signatures`.
|
|
102
|
+
|
|
103
|
+
Docs: <https://signaturekit.dev/en-US/docs/providers/clicksign>.
|
|
22
104
|
|
|
23
105
|
## License
|
|
24
106
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,80 @@
|
|
|
1
|
-
import { SignatureKitError } from "@signature-kit/
|
|
2
|
-
import
|
|
3
|
-
import { SignatureHttpClient } from "@signature-kit/core/http";
|
|
1
|
+
import { SignatureKitError } from "@signature-kit/signatures";
|
|
2
|
+
import { SignatureHttpClient } from "@signature-kit/http";
|
|
4
3
|
import { Resource } from "alchemy";
|
|
5
4
|
import * as Provider from "alchemy/Provider";
|
|
6
|
-
import {
|
|
5
|
+
import { Duration, Effect, Layer, Redacted, Schema } from "effect";
|
|
6
|
+
export declare const ClicksignProviderId = "clicksign";
|
|
7
|
+
export declare const ClicksignSignatureRequestStateSchema: Schema.Literals<readonly ["draft", "sent", "completed", "cancelled", "deleted", "declined", "expired"]>;
|
|
8
|
+
export type ClicksignSignatureRequestState = (typeof ClicksignSignatureRequestStateSchema)["Type"];
|
|
9
|
+
export declare const ClicksignDocumentInputSchema: Schema.Struct<{
|
|
10
|
+
readonly fileName: Schema.NonEmptyString;
|
|
11
|
+
readonly mimeType: Schema.NonEmptyString;
|
|
12
|
+
readonly content: Schema.Uint8Array;
|
|
13
|
+
}>;
|
|
14
|
+
export type ClicksignDocumentInput = (typeof ClicksignDocumentInputSchema)["Type"];
|
|
15
|
+
export declare const ClicksignDocumentPropsSchema: Schema.Struct<{
|
|
16
|
+
readonly fileName: Schema.NonEmptyString;
|
|
17
|
+
readonly mimeType: Schema.NonEmptyString;
|
|
18
|
+
readonly contentBase64: Schema.ConstraintDecoder<string, never>;
|
|
19
|
+
}>;
|
|
20
|
+
export type ClicksignDocumentProps = (typeof ClicksignDocumentPropsSchema)["Type"];
|
|
21
|
+
export declare const ClicksignSignerRoleSchema: Schema.Literals<readonly ["approver", "signer"]>;
|
|
22
|
+
export type ClicksignSignerRole = (typeof ClicksignSignerRoleSchema)["Type"];
|
|
23
|
+
export declare const ClicksignSignerSchema: Schema.Struct<{
|
|
24
|
+
readonly name: Schema.NonEmptyString;
|
|
25
|
+
readonly email: Schema.NonEmptyString;
|
|
26
|
+
readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
|
|
27
|
+
readonly routingOrder: Schema.optional<Schema.Finite>;
|
|
28
|
+
}>;
|
|
29
|
+
export type ClicksignSigner = (typeof ClicksignSignerSchema)["Type"];
|
|
30
|
+
export declare const ClicksignSignatureRequestInputSchema: Schema.Struct<{
|
|
31
|
+
readonly title: Schema.NonEmptyString;
|
|
32
|
+
readonly message: Schema.optional<Schema.NonEmptyString>;
|
|
33
|
+
readonly documents: Schema.Tuple<readonly [Schema.Struct<{
|
|
34
|
+
readonly fileName: Schema.NonEmptyString;
|
|
35
|
+
readonly mimeType: Schema.NonEmptyString;
|
|
36
|
+
readonly content: Schema.Uint8Array;
|
|
37
|
+
}>]>;
|
|
38
|
+
readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
|
|
39
|
+
readonly name: Schema.NonEmptyString;
|
|
40
|
+
readonly email: Schema.NonEmptyString;
|
|
41
|
+
readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
|
|
42
|
+
readonly routingOrder: Schema.optional<Schema.Finite>;
|
|
43
|
+
}>>;
|
|
44
|
+
readonly send: Schema.optional<Schema.Boolean>;
|
|
45
|
+
readonly expiresAt: Schema.optional<Schema.Date>;
|
|
46
|
+
readonly redirectUrl: Schema.optional<Schema.NonEmptyString>;
|
|
47
|
+
}>;
|
|
48
|
+
export type ClicksignSignatureRequestInput = (typeof ClicksignSignatureRequestInputSchema)["Type"];
|
|
49
|
+
export declare const ClicksignSignatureRequestPropsSchema: Schema.Struct<{
|
|
50
|
+
readonly title: Schema.NonEmptyString;
|
|
51
|
+
readonly message: Schema.optional<Schema.NonEmptyString>;
|
|
52
|
+
readonly documents: Schema.Tuple<readonly [Schema.Struct<{
|
|
53
|
+
readonly fileName: Schema.NonEmptyString;
|
|
54
|
+
readonly mimeType: Schema.NonEmptyString;
|
|
55
|
+
readonly contentBase64: Schema.ConstraintDecoder<string, never>;
|
|
56
|
+
}>]>;
|
|
57
|
+
readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
|
|
58
|
+
readonly name: Schema.NonEmptyString;
|
|
59
|
+
readonly email: Schema.NonEmptyString;
|
|
60
|
+
readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
|
|
61
|
+
readonly routingOrder: Schema.optional<Schema.Finite>;
|
|
62
|
+
}>>;
|
|
63
|
+
readonly send: Schema.optional<Schema.Boolean>;
|
|
64
|
+
readonly expiresAt: Schema.optional<Schema.Date>;
|
|
65
|
+
readonly redirectUrl: Schema.optional<Schema.NonEmptyString>;
|
|
66
|
+
}>;
|
|
67
|
+
export type ClicksignSignatureRequestProps = (typeof ClicksignSignatureRequestPropsSchema)["Type"];
|
|
68
|
+
export declare const ClicksignSignatureRequestAttributesSchema: Schema.Struct<{
|
|
69
|
+
readonly provider: Schema.Literal<"clicksign">;
|
|
70
|
+
readonly id: Schema.NonEmptyString;
|
|
71
|
+
readonly state: Schema.Literals<readonly ["draft", "sent", "completed", "cancelled", "deleted", "declined", "expired"]>;
|
|
72
|
+
readonly providerStatus: Schema.optional<Schema.String>;
|
|
73
|
+
readonly signingUrl: Schema.optional<Schema.String>;
|
|
74
|
+
readonly detailsUrl: Schema.optional<Schema.String>;
|
|
75
|
+
readonly downloadUrl: Schema.optional<Schema.String>;
|
|
76
|
+
}>;
|
|
77
|
+
export type ClicksignSignatureRequestAttributes = (typeof ClicksignSignatureRequestAttributesSchema)["Type"];
|
|
7
78
|
declare const ClicksignEnvironmentSchema: Schema.Literals<readonly ["production", "sandbox"]>;
|
|
8
79
|
export type ClicksignEnvironment = (typeof ClicksignEnvironmentSchema)["Type"];
|
|
9
80
|
declare const ClicksignLocaleSchema: Schema.Literals<readonly ["en-US", "pt-BR"]>;
|
|
@@ -16,27 +87,31 @@ export declare const ClicksignProviderOptionsSchema: Schema.Struct<{
|
|
|
16
87
|
readonly autoClose: Schema.optional<Schema.Boolean>;
|
|
17
88
|
}>;
|
|
18
89
|
export type ClicksignProviderOptions = (typeof ClicksignProviderOptionsSchema)["Type"];
|
|
19
|
-
export type ClicksignSignatureRequest = Resource<"SignatureKit.ClicksignSignatureRequest",
|
|
90
|
+
export type ClicksignSignatureRequest = Resource<"SignatureKit.ClicksignSignatureRequest", ClicksignSignatureRequestProps, ClicksignSignatureRequestAttributes>;
|
|
20
91
|
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
92
|
declare const ClicksignProviders_base: Provider.ProviderCollection<ClicksignProviders, "@signature-kit/clicksign/Providers">;
|
|
33
|
-
|
|
93
|
+
declare class ClicksignProviders extends ClicksignProviders_base {
|
|
34
94
|
}
|
|
35
|
-
export declare const providers: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignProviders,
|
|
36
|
-
export declare const getClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<
|
|
37
|
-
export declare const listClicksignSignatureRequests: (options: ClicksignProviderOptions) => Effect.Effect<readonly
|
|
95
|
+
export declare const providers: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignProviders, never, SignatureHttpClient>;
|
|
96
|
+
export declare const getClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<ClicksignSignatureRequestAttributes, SignatureKitError, SignatureHttpClient>;
|
|
97
|
+
export declare const listClicksignSignatureRequests: (options: ClicksignProviderOptions) => Effect.Effect<readonly ClicksignSignatureRequestAttributes[], SignatureKitError, SignatureHttpClient>;
|
|
38
98
|
export declare const cancelClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
39
99
|
export declare const deleteClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
40
100
|
export declare const downloadClicksignSignedDocument: (options: ClicksignProviderOptions, id: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
|
|
101
|
+
export declare const waitForClicksignSignatureRequest: (options: {
|
|
102
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
103
|
+
readonly environment?: "production" | "sandbox" | undefined;
|
|
104
|
+
readonly baseUrl?: string | undefined;
|
|
105
|
+
readonly locale?: "en-US" | "pt-BR" | undefined;
|
|
106
|
+
readonly autoClose?: boolean | undefined;
|
|
107
|
+
}, id: string, pollInterval: Duration.Duration) => Effect.Effect<{
|
|
108
|
+
readonly provider: "clicksign";
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly state: "cancelled" | "completed" | "declined" | "deleted" | "draft" | "expired" | "sent";
|
|
111
|
+
readonly providerStatus?: string | undefined;
|
|
112
|
+
readonly signingUrl?: string | undefined;
|
|
113
|
+
readonly detailsUrl?: string | undefined;
|
|
114
|
+
readonly downloadUrl?: string | undefined;
|
|
115
|
+
}, SignatureKitError, SignatureHttpClient>;
|
|
41
116
|
export {};
|
|
42
117
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,106 @@
|
|
|
1
|
-
import { bytesToBase64 } from "@signature-kit/crypto/base64";
|
|
2
|
-
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue,
|
|
3
|
-
import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/
|
|
1
|
+
import { base64ToBytes, bytesToBase64 } from "@signature-kit/crypto/base64";
|
|
2
|
+
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, redactedStringSchema, } from "@signature-kit/signatures";
|
|
3
|
+
import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/http";
|
|
4
4
|
import { Resource } from "alchemy";
|
|
5
5
|
import * as Provider from "alchemy/Provider";
|
|
6
|
-
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
7
|
-
const
|
|
6
|
+
import { Context, Duration, Effect, Layer, Match, Option, Redacted, Schedule, Schema, Stream, } from "effect";
|
|
7
|
+
const ClicksignSchemaName = {
|
|
8
|
+
providerOptions: "ClicksignProviderOptions",
|
|
9
|
+
signatureRequestProps: "ClicksignSignatureRequestProps",
|
|
10
|
+
documentResult: "ClicksignDocumentResult",
|
|
11
|
+
signerResult: "ClicksignSignerResult",
|
|
12
|
+
listResult: "ClicksignListResult",
|
|
13
|
+
documentsResult: "ClicksignDocumentsResult",
|
|
14
|
+
};
|
|
15
|
+
const ClicksignOperation = {
|
|
16
|
+
download: "clicksign.download",
|
|
17
|
+
};
|
|
18
|
+
const base64String = Schema.String.check(Schema.isBase64());
|
|
19
|
+
export const ClicksignProviderId = "clicksign";
|
|
20
|
+
const PROVIDER = ClicksignProviderId;
|
|
21
|
+
export const ClicksignSignatureRequestStateSchema = Schema.Literals([
|
|
22
|
+
"draft",
|
|
23
|
+
"sent",
|
|
24
|
+
"completed",
|
|
25
|
+
"cancelled",
|
|
26
|
+
"deleted",
|
|
27
|
+
"declined",
|
|
28
|
+
"expired",
|
|
29
|
+
]);
|
|
30
|
+
export const ClicksignDocumentInputSchema = Schema.Struct({
|
|
31
|
+
fileName: Schema.NonEmptyString,
|
|
32
|
+
mimeType: Schema.NonEmptyString,
|
|
33
|
+
content: Schema.Uint8Array,
|
|
34
|
+
});
|
|
35
|
+
export const ClicksignDocumentPropsSchema = Schema.Struct({
|
|
36
|
+
fileName: Schema.NonEmptyString,
|
|
37
|
+
mimeType: Schema.NonEmptyString,
|
|
38
|
+
contentBase64: base64String,
|
|
39
|
+
});
|
|
40
|
+
export const ClicksignSignerRoleSchema = Schema.Literals(["approver", "signer"]);
|
|
41
|
+
export const ClicksignSignerSchema = Schema.Struct({
|
|
42
|
+
name: Schema.NonEmptyString,
|
|
43
|
+
email: Schema.NonEmptyString,
|
|
44
|
+
role: Schema.optional(ClicksignSignerRoleSchema),
|
|
45
|
+
routingOrder: Schema.optional(Schema.Finite),
|
|
46
|
+
});
|
|
47
|
+
export const ClicksignSignatureRequestInputSchema = Schema.Struct({
|
|
48
|
+
title: Schema.NonEmptyString,
|
|
49
|
+
message: Schema.optional(Schema.NonEmptyString),
|
|
50
|
+
documents: Schema.Tuple([ClicksignDocumentInputSchema]),
|
|
51
|
+
recipients: Schema.NonEmptyArray(ClicksignSignerSchema),
|
|
52
|
+
send: Schema.optional(Schema.Boolean),
|
|
53
|
+
expiresAt: Schema.optional(Schema.Date),
|
|
54
|
+
redirectUrl: Schema.optional(Schema.NonEmptyString),
|
|
55
|
+
});
|
|
56
|
+
export const ClicksignSignatureRequestPropsSchema = Schema.Struct({
|
|
57
|
+
title: Schema.NonEmptyString,
|
|
58
|
+
message: Schema.optional(Schema.NonEmptyString),
|
|
59
|
+
documents: Schema.Tuple([ClicksignDocumentPropsSchema]),
|
|
60
|
+
recipients: Schema.NonEmptyArray(ClicksignSignerSchema),
|
|
61
|
+
send: Schema.optional(Schema.Boolean),
|
|
62
|
+
expiresAt: Schema.optional(Schema.Date),
|
|
63
|
+
redirectUrl: Schema.optional(Schema.NonEmptyString),
|
|
64
|
+
});
|
|
65
|
+
export const ClicksignSignatureRequestAttributesSchema = Schema.Struct({
|
|
66
|
+
provider: Schema.Literal(PROVIDER),
|
|
67
|
+
id: Schema.NonEmptyString,
|
|
68
|
+
state: ClicksignSignatureRequestStateSchema,
|
|
69
|
+
providerStatus: Schema.optional(Schema.String),
|
|
70
|
+
signingUrl: Schema.optional(Schema.String),
|
|
71
|
+
detailsUrl: Schema.optional(Schema.String),
|
|
72
|
+
downloadUrl: Schema.optional(Schema.String),
|
|
73
|
+
});
|
|
74
|
+
const clicksignSignatureRequestNoopDiff = { action: "noop" };
|
|
75
|
+
const clicksignSignatureRequestDiff = ({ olds, }) => Effect.succeed(olds === undefined ? undefined : clicksignSignatureRequestNoopDiff);
|
|
76
|
+
const clicksignSignatureRequestInputFromProps = Effect.fn(function* (props) {
|
|
77
|
+
const [document] = props.documents;
|
|
78
|
+
const content = yield* base64ToBytes(document.contentBase64).pipe(Effect.orDie);
|
|
79
|
+
const documents = [
|
|
80
|
+
{
|
|
81
|
+
fileName: document.fileName,
|
|
82
|
+
mimeType: document.mimeType,
|
|
83
|
+
content,
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
return {
|
|
87
|
+
title: props.title,
|
|
88
|
+
documents,
|
|
89
|
+
recipients: props.recipients,
|
|
90
|
+
...(props.message === undefined ? {} : { message: props.message }),
|
|
91
|
+
...(props.send === undefined ? {} : { send: props.send }),
|
|
92
|
+
...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
|
|
93
|
+
...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
const clicksignSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(ClicksignSignatureRequestPropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
97
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
98
|
+
retryable: false,
|
|
99
|
+
provider: PROVIDER,
|
|
100
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
101
|
+
schemaName: ClicksignSchemaName.signatureRequestProps,
|
|
102
|
+
issueMessage: String(issue),
|
|
103
|
+
})), Effect.flatMap(clicksignSignatureRequestInputFromProps));
|
|
8
104
|
const CLICKSIGN_PROVIDER_COLLECTION_ID = "@signature-kit/clicksign/Providers";
|
|
9
105
|
const SANDBOX_BASE_URL = "https://sandbox.clicksign.com/api/v1";
|
|
10
106
|
const PRODUCTION_BASE_URL = "https://app.clicksign.com/api/v1";
|
|
@@ -36,13 +132,10 @@ const ClicksignSignerResultSchema = Schema.Struct({
|
|
|
36
132
|
const ClicksignListResultSchema = Schema.Struct({
|
|
37
133
|
list: Schema.Struct({ request_signature_key: Schema.NonEmptyString }),
|
|
38
134
|
});
|
|
39
|
-
const ClicksignGetDocumentResponseSchema = Schema.Struct({
|
|
40
|
-
document: ClicksignDocumentSchema,
|
|
41
|
-
});
|
|
42
135
|
const ClicksignPageInfosSchema = Schema.Struct({
|
|
43
|
-
total_pages: Schema.optional(Schema.Union([Schema.
|
|
44
|
-
current_page: Schema.optional(Schema.Union([Schema.
|
|
45
|
-
next_page: Schema.optional(Schema.Union([Schema.
|
|
136
|
+
total_pages: Schema.optional(Schema.Union([Schema.Finite, Schema.String])),
|
|
137
|
+
current_page: Schema.optional(Schema.Union([Schema.Finite, Schema.String])),
|
|
138
|
+
next_page: Schema.optional(Schema.Union([Schema.Finite, Schema.String, Schema.Null])),
|
|
46
139
|
last_page: Schema.optional(Schema.Boolean),
|
|
47
140
|
});
|
|
48
141
|
const ClicksignDocumentsResultSchema = Schema.Struct({
|
|
@@ -51,29 +144,25 @@ const ClicksignDocumentsResultSchema = Schema.Struct({
|
|
|
51
144
|
});
|
|
52
145
|
const clicksignPathId = (id) => encodeURIComponent(id);
|
|
53
146
|
const clicksignDocumentPath = (id) => `/documents/${clicksignPathId(id)}`;
|
|
54
|
-
const
|
|
55
|
-
|
|
147
|
+
const ClicksignStatusSchema = Schema.Literals([
|
|
148
|
+
"draft",
|
|
149
|
+
"completed",
|
|
150
|
+
"signed",
|
|
151
|
+
"closed",
|
|
152
|
+
"cancelled",
|
|
153
|
+
"canceled",
|
|
154
|
+
"deleted",
|
|
155
|
+
"declined",
|
|
156
|
+
"expired",
|
|
157
|
+
]);
|
|
158
|
+
const isClicksignStatus = Schema.is(ClicksignStatusSchema);
|
|
159
|
+
const toClicksignSignatureRequestAttributesState = (status) => {
|
|
56
160
|
if (status === undefined)
|
|
57
161
|
return "sent";
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
case "signed":
|
|
63
|
-
case "closed":
|
|
64
|
-
return "completed";
|
|
65
|
-
case "cancelled":
|
|
66
|
-
case "canceled":
|
|
67
|
-
return "cancelled";
|
|
68
|
-
case "deleted":
|
|
69
|
-
return "deleted";
|
|
70
|
-
case "declined":
|
|
71
|
-
return "declined";
|
|
72
|
-
case "expired":
|
|
73
|
-
return "expired";
|
|
74
|
-
default:
|
|
75
|
-
return "sent";
|
|
76
|
-
}
|
|
162
|
+
const normalized = status.toLowerCase();
|
|
163
|
+
if (!isClicksignStatus(normalized))
|
|
164
|
+
return "sent";
|
|
165
|
+
return Match.value(normalized).pipe(Match.when("draft", () => "draft"), Match.whenOr("completed", "signed", "closed", () => "completed"), Match.whenOr("cancelled", "canceled", () => "cancelled"), Match.when("deleted", () => "deleted"), Match.when("declined", () => "declined"), Match.when("expired", () => "expired"), Match.orElse(() => "sent"));
|
|
77
166
|
};
|
|
78
167
|
const resolveClicksignSignedDocumentUrl = (document) => {
|
|
79
168
|
const signedFile = document.downloads?.signed_file_url;
|
|
@@ -104,15 +193,15 @@ const clicksignListNextPage = (pageInfos, currentPage) => {
|
|
|
104
193
|
const totalPages = parseClicksignPageNumber(pageInfos.total_pages);
|
|
105
194
|
return totalPages === undefined || totalPages <= currentPage ? undefined : currentPage + 1;
|
|
106
195
|
};
|
|
107
|
-
const
|
|
196
|
+
const toClicksignSignatureRequestAttributes = (baseUrl, document) => {
|
|
108
197
|
const downloadUrl = resolveClicksignSignedDocumentUrl(document);
|
|
109
198
|
return {
|
|
110
199
|
provider: PROVIDER,
|
|
111
200
|
id: document.key,
|
|
112
|
-
state:
|
|
113
|
-
providerStatus: document.status,
|
|
201
|
+
state: toClicksignSignatureRequestAttributesState(document.status),
|
|
202
|
+
...(document.status === undefined ? {} : { providerStatus: document.status }),
|
|
114
203
|
detailsUrl: `${baseUrl}${clicksignDocumentPath(document.key)}`,
|
|
115
|
-
downloadUrl
|
|
204
|
+
...(downloadUrl === undefined ? {} : { downloadUrl }),
|
|
116
205
|
};
|
|
117
206
|
};
|
|
118
207
|
const getClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http
|
|
@@ -121,30 +210,27 @@ const getClicksignSignatureRequestInternal = (http, options, baseUrl, id) => htt
|
|
|
121
210
|
method: "GET",
|
|
122
211
|
...withAccessToken(baseUrl, clicksignDocumentPath(id), options.accessToken),
|
|
123
212
|
headers: { "Content-Type": "application/json" },
|
|
124
|
-
},
|
|
125
|
-
.pipe(Effect.map((result) =>
|
|
126
|
-
const listClicksignSignatureRequestsInternal = (http, options, baseUrl) => {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
return fetchPage(1);
|
|
144
|
-
};
|
|
213
|
+
}, ClicksignDocumentResultSchema, ClicksignSchemaName.documentResult)
|
|
214
|
+
.pipe(Effect.map((result) => toClicksignSignatureRequestAttributes(baseUrl, result.document)));
|
|
215
|
+
const listClicksignSignatureRequestsInternal = (http, options, baseUrl) => Stream.paginate(1, (page) => {
|
|
216
|
+
const pagePath = `/documents?page=${String(page)}`;
|
|
217
|
+
return http
|
|
218
|
+
.requestJson({
|
|
219
|
+
provider: PROVIDER,
|
|
220
|
+
method: "GET",
|
|
221
|
+
...withAccessToken(baseUrl, pagePath, options.accessToken),
|
|
222
|
+
}, ClicksignDocumentsResultSchema, ClicksignSchemaName.documentsResult)
|
|
223
|
+
.pipe(Effect.map((result) => {
|
|
224
|
+
const nextPage = clicksignListNextPage(result.page_infos, page);
|
|
225
|
+
return [
|
|
226
|
+
result.documents.map((document) => toClicksignSignatureRequestAttributes(baseUrl, document)),
|
|
227
|
+
nextPage === undefined ? Option.none() : Option.some(nextPage),
|
|
228
|
+
];
|
|
229
|
+
}));
|
|
230
|
+
}).pipe(Stream.runCollect);
|
|
145
231
|
const cancelClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http.requestVoid({
|
|
146
232
|
provider: PROVIDER,
|
|
147
|
-
method: "
|
|
233
|
+
method: "PATCH",
|
|
148
234
|
...withAccessToken(baseUrl, `${clicksignDocumentPath(id)}/cancel`, options.accessToken),
|
|
149
235
|
});
|
|
150
236
|
const deleteClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http
|
|
@@ -154,6 +240,13 @@ const deleteClicksignSignatureRequestInternal = (http, options, baseUrl, id) =>
|
|
|
154
240
|
...withAccessToken(baseUrl, clicksignDocumentPath(id), options.accessToken),
|
|
155
241
|
})
|
|
156
242
|
.pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.void));
|
|
243
|
+
const shouldRollbackClicksignCreate = (error) => error.code === SignatureKitErrorCodeValue.http &&
|
|
244
|
+
error.status !== undefined &&
|
|
245
|
+
error.status >= 400 &&
|
|
246
|
+
error.status < 500 &&
|
|
247
|
+
error.status !== 408 &&
|
|
248
|
+
error.status !== 409 &&
|
|
249
|
+
error.status !== 429;
|
|
157
250
|
const isAbsoluteHttpUrl = (value) => value.startsWith("http://") || value.startsWith("https://");
|
|
158
251
|
const clicksignDownloadPath = (path) => (path.startsWith("/") ? path : `/${path}`);
|
|
159
252
|
const isClicksignDownloadHost = (baseUrl, downloadUrl) => {
|
|
@@ -168,8 +261,11 @@ const clicksignDownloadTarget = (baseUrl, downloadUrl, accessToken) => {
|
|
|
168
261
|
if (!isClicksignDownloadHost(baseUrl, downloadUrl))
|
|
169
262
|
return { url: downloadUrl };
|
|
170
263
|
const parsed = new URL(downloadUrl);
|
|
171
|
-
if (parsed.searchParams.has("access_token"))
|
|
172
|
-
|
|
264
|
+
if (parsed.searchParams.has("access_token")) {
|
|
265
|
+
const diagnosticUrl = new URL(downloadUrl);
|
|
266
|
+
diagnosticUrl.searchParams.set("access_token", "<redacted>");
|
|
267
|
+
return { url: downloadUrl, diagnosticUrl: diagnosticUrl.toString() };
|
|
268
|
+
}
|
|
173
269
|
const targetUrl = new URL(downloadUrl);
|
|
174
270
|
const diagnosticUrl = new URL(downloadUrl);
|
|
175
271
|
targetUrl.searchParams.set("access_token", Redacted.value(accessToken));
|
|
@@ -185,23 +281,25 @@ const downloadClicksignSignedDocumentInternal = (http, options, baseUrl, id) =>
|
|
|
185
281
|
...clicksignDownloadTarget(baseUrl, signedDocumentUrl, options.accessToken),
|
|
186
282
|
});
|
|
187
283
|
}
|
|
188
|
-
return
|
|
284
|
+
return Effect.fail(new SignatureKitError({
|
|
285
|
+
code: SignatureKitErrorCodeValue.unsupportedOperation,
|
|
286
|
+
retryable: false,
|
|
189
287
|
provider: PROVIDER,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
288
|
+
operation: ClicksignOperation.download,
|
|
289
|
+
reason: `Clicksign document ${id} has no signed file to download yet (status: ${request.providerStatus ?? "unknown"}).`,
|
|
290
|
+
}));
|
|
193
291
|
}));
|
|
194
292
|
export const ClicksignSignatureRequest = Resource("SignatureKit.ClicksignSignatureRequest", { defaultRemovalPolicy: "retain" });
|
|
195
|
-
|
|
293
|
+
class ClicksignCredentials extends Context.Service()("@signature-kit/clicksign/Credentials") {
|
|
196
294
|
}
|
|
197
|
-
|
|
295
|
+
const clicksignCredentialsLayer = (options) => Layer.effect(ClicksignCredentials, Effect.cached(Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
198
296
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
199
297
|
retryable: false,
|
|
200
298
|
provider: PROVIDER,
|
|
201
299
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
202
|
-
schemaName:
|
|
300
|
+
schemaName: ClicksignSchemaName.providerOptions,
|
|
203
301
|
issueMessage: String(issue),
|
|
204
|
-
}))));
|
|
302
|
+
})))));
|
|
205
303
|
const clicksignBaseUrl = (options) => {
|
|
206
304
|
if (options.baseUrl !== undefined)
|
|
207
305
|
return normalizedBaseUrl(options.baseUrl);
|
|
@@ -232,11 +330,10 @@ const createDocument = (http, options, baseUrl, input, document) => http
|
|
|
232
330
|
deadline_at: input.expiresAt?.toISOString(),
|
|
233
331
|
auto_close: options.autoClose ?? true,
|
|
234
332
|
locale: options.locale ?? "pt-BR",
|
|
235
|
-
sequence_enabled: input.recipients.
|
|
236
|
-
input.recipients.some((recipient) => recipient.routingOrder !== undefined),
|
|
333
|
+
sequence_enabled: input.recipients.some((recipient) => recipient.routingOrder !== undefined),
|
|
237
334
|
},
|
|
238
335
|
}),
|
|
239
|
-
}, ClicksignDocumentResultSchema,
|
|
336
|
+
}, ClicksignDocumentResultSchema, ClicksignSchemaName.documentResult)
|
|
240
337
|
.pipe(Effect.map((result) => result.document.key));
|
|
241
338
|
const createSigner = (http, options, baseUrl, recipient) => http
|
|
242
339
|
.requestJson({
|
|
@@ -252,7 +349,7 @@ const createSigner = (http, options, baseUrl, recipient) => http
|
|
|
252
349
|
has_documentation: false,
|
|
253
350
|
},
|
|
254
351
|
}),
|
|
255
|
-
}, ClicksignSignerResultSchema,
|
|
352
|
+
}, ClicksignSignerResultSchema, ClicksignSchemaName.signerResult)
|
|
256
353
|
.pipe(Effect.map((result) => result.signer.key));
|
|
257
354
|
const linkRecipient = (http, options, baseUrl, documentKey, signerKey, recipient, index, message) => http
|
|
258
355
|
.requestJson({
|
|
@@ -269,7 +366,7 @@ const linkRecipient = (http, options, baseUrl, documentKey, signerKey, recipient
|
|
|
269
366
|
message,
|
|
270
367
|
},
|
|
271
368
|
}),
|
|
272
|
-
}, ClicksignListResultSchema,
|
|
369
|
+
}, ClicksignListResultSchema, ClicksignSchemaName.listResult)
|
|
273
370
|
.pipe(Effect.map((result) => result.list.request_signature_key));
|
|
274
371
|
const notifyRecipient = (http, options, baseUrl, requestSignatureKey, input) => http.requestVoid({
|
|
275
372
|
provider: PROVIDER,
|
|
@@ -282,65 +379,55 @@ const notifyRecipient = (http, options, baseUrl, requestSignatureKey, input) =>
|
|
|
282
379
|
url: input.redirectUrl,
|
|
283
380
|
}),
|
|
284
381
|
});
|
|
285
|
-
const
|
|
286
|
-
const document = input.documents
|
|
287
|
-
|
|
288
|
-
return Effect.fail(new SignatureKitError({
|
|
289
|
-
code: SignatureKitErrorCodeValue.unsupportedOperation,
|
|
290
|
-
retryable: false,
|
|
291
|
-
provider: PROVIDER,
|
|
292
|
-
operation: SignatureKitOperationValue.remoteCreate,
|
|
293
|
-
reason: "Clicksign API v1 supports one uploaded document per signature request.",
|
|
294
|
-
}));
|
|
295
|
-
}
|
|
296
|
-
return createDocument(http, options, baseUrl, input, document).pipe(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.flatMap((requestSignatureKeys) => input.send === false
|
|
382
|
+
const createClicksignSignatureRequest = (http, options, baseUrl, input) => {
|
|
383
|
+
const [document] = input.documents;
|
|
384
|
+
return createDocument(http, options, baseUrl, input, document).pipe(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))), { concurrency: 4 }).pipe(Effect.catchIf(shouldRollbackClicksignCreate, (error) => deleteClicksignSignatureRequestInternal(http, options, baseUrl, documentKey).pipe(Effect.ignore, Effect.flatMap(() => Effect.fail(error)))), Effect.flatMap((requestSignatureKeys) => input.send === false
|
|
297
385
|
? Effect.succeed({ documentKey })
|
|
298
|
-
: Effect.forEach(requestSignatureKeys, (requestSignatureKey) => notifyRecipient(http, options, baseUrl, requestSignatureKey, input), { discard: true }).pipe(Effect.as({ documentKey })))
|
|
299
|
-
code: error.code,
|
|
300
|
-
retryable: error.retryable,
|
|
301
|
-
provider: error.provider ?? PROVIDER,
|
|
302
|
-
operation: SignatureKitOperationValue.remoteCreate,
|
|
303
|
-
status: error.status,
|
|
304
|
-
schemaName: error.schemaName,
|
|
305
|
-
issueMessage: error.issueMessage,
|
|
306
|
-
reason: error.reason === undefined
|
|
307
|
-
? `Clicksign create for document ${documentKey} failed after document creation.`
|
|
308
|
-
: `Clicksign create for document ${documentKey} failed after document creation: ${error.reason}`,
|
|
309
|
-
})))), Effect.map(({ documentKey }) => ({
|
|
386
|
+
: Effect.forEach(requestSignatureKeys, (requestSignatureKey) => notifyRecipient(http, options, baseUrl, requestSignatureKey, input), { concurrency: 4, discard: true }).pipe(Effect.as({ documentKey }))))), Effect.map(({ documentKey }) => ({
|
|
310
387
|
provider: PROVIDER,
|
|
311
388
|
id: documentKey,
|
|
312
389
|
state: input.send === false ? "draft" : "sent",
|
|
313
390
|
})));
|
|
314
391
|
};
|
|
315
|
-
|
|
316
|
-
const
|
|
392
|
+
const clicksignSignatureRequestProvider = Provider.effect(ClicksignSignatureRequest, Effect.gen(function* () {
|
|
393
|
+
const credentials = yield* ClicksignCredentials;
|
|
317
394
|
const http = yield* SignatureHttpClient;
|
|
318
|
-
const baseUrl = clicksignBaseUrl(options);
|
|
319
395
|
return ClicksignSignatureRequest.Provider.of({
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
396
|
+
nuke: { skip: true },
|
|
397
|
+
diff: clicksignSignatureRequestDiff,
|
|
398
|
+
list: () => Effect.succeed([]),
|
|
399
|
+
read: Effect.fn(function* ({ output }) {
|
|
400
|
+
if (output === undefined)
|
|
401
|
+
return undefined;
|
|
402
|
+
const options = yield* credentials;
|
|
403
|
+
const baseUrl = clicksignBaseUrl(options);
|
|
404
|
+
return yield* getClicksignSignatureRequestInternal(http, options, baseUrl, output.id).pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined)));
|
|
405
|
+
}),
|
|
325
406
|
reconcile: Effect.fn(function* ({ news, output }) {
|
|
326
407
|
if (output !== undefined)
|
|
327
408
|
return output;
|
|
328
|
-
const
|
|
329
|
-
|
|
409
|
+
const options = yield* credentials;
|
|
410
|
+
const baseUrl = clicksignBaseUrl(options);
|
|
411
|
+
const input = yield* clicksignSignatureRequestInputFromResourceProps(news);
|
|
412
|
+
return yield* createClicksignSignatureRequest(http, options, baseUrl, input);
|
|
413
|
+
}),
|
|
414
|
+
delete: Effect.fn(function* ({ output }) {
|
|
415
|
+
const options = yield* credentials;
|
|
416
|
+
const baseUrl = clicksignBaseUrl(options);
|
|
417
|
+
return yield* deleteClicksignSignatureRequestInternal(http, options, baseUrl, output.id);
|
|
330
418
|
}),
|
|
331
|
-
delete: ({ output }) => deleteClicksignSignatureRequestInternal(http, options, baseUrl, output.id),
|
|
332
419
|
});
|
|
333
420
|
}));
|
|
334
|
-
|
|
421
|
+
class ClicksignProviders extends Provider.ProviderCollection()(CLICKSIGN_PROVIDER_COLLECTION_ID) {
|
|
335
422
|
}
|
|
336
|
-
export const providers = (options) => Layer.effect(ClicksignProviders, Provider.collection([ClicksignSignatureRequest])).pipe(Layer.provide(
|
|
423
|
+
export const providers = (options) => Layer.effect(ClicksignProviders, Provider.collection([ClicksignSignatureRequest])).pipe(Layer.provide(Layer.fresh(clicksignSignatureRequestProvider)), Layer.provide(clicksignCredentialsLayer(options)));
|
|
337
424
|
export const getClicksignSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
338
425
|
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
339
426
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
340
427
|
retryable: false,
|
|
341
428
|
provider: PROVIDER,
|
|
342
429
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
343
|
-
schemaName:
|
|
430
|
+
schemaName: ClicksignSchemaName.providerOptions,
|
|
344
431
|
issueMessage: String(issue),
|
|
345
432
|
})));
|
|
346
433
|
const http = yield* SignatureHttpClient;
|
|
@@ -352,7 +439,7 @@ export const listClicksignSignatureRequests = (options) => Effect.gen(function*
|
|
|
352
439
|
retryable: false,
|
|
353
440
|
provider: PROVIDER,
|
|
354
441
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
355
|
-
schemaName:
|
|
442
|
+
schemaName: ClicksignSchemaName.providerOptions,
|
|
356
443
|
issueMessage: String(issue),
|
|
357
444
|
})));
|
|
358
445
|
const http = yield* SignatureHttpClient;
|
|
@@ -364,7 +451,7 @@ export const cancelClicksignSignatureRequest = (options, id) => Effect.gen(funct
|
|
|
364
451
|
retryable: false,
|
|
365
452
|
provider: PROVIDER,
|
|
366
453
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
367
|
-
schemaName:
|
|
454
|
+
schemaName: ClicksignSchemaName.providerOptions,
|
|
368
455
|
issueMessage: String(issue),
|
|
369
456
|
})));
|
|
370
457
|
const http = yield* SignatureHttpClient;
|
|
@@ -376,7 +463,7 @@ export const deleteClicksignSignatureRequest = (options, id) => Effect.gen(funct
|
|
|
376
463
|
retryable: false,
|
|
377
464
|
provider: PROVIDER,
|
|
378
465
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
379
|
-
schemaName:
|
|
466
|
+
schemaName: ClicksignSchemaName.providerOptions,
|
|
380
467
|
issueMessage: String(issue),
|
|
381
468
|
})));
|
|
382
469
|
const http = yield* SignatureHttpClient;
|
|
@@ -388,9 +475,24 @@ export const downloadClicksignSignedDocument = (options, id) => Effect.gen(funct
|
|
|
388
475
|
retryable: false,
|
|
389
476
|
provider: PROVIDER,
|
|
390
477
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
391
|
-
schemaName:
|
|
478
|
+
schemaName: ClicksignSchemaName.providerOptions,
|
|
392
479
|
issueMessage: String(issue),
|
|
393
480
|
})));
|
|
394
481
|
const http = yield* SignatureHttpClient;
|
|
395
482
|
return yield* downloadClicksignSignedDocumentInternal(http, valid, clicksignBaseUrl(valid), id);
|
|
396
483
|
});
|
|
484
|
+
export const waitForClicksignSignatureRequest = Effect.fn(function* (options, id, pollInterval) {
|
|
485
|
+
const interval = yield* Schema.decodeUnknownEffect(Schema.Duration.check(Schema.makeFilter((value) => Duration.isFinite(value) && Duration.isPositive(value))))(pollInterval).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
486
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
487
|
+
retryable: false,
|
|
488
|
+
provider: PROVIDER,
|
|
489
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
490
|
+
schemaName: "ClicksignPollInterval",
|
|
491
|
+
issueMessage: String(issue),
|
|
492
|
+
reason: "Polling requires a positive, finite interval.",
|
|
493
|
+
})));
|
|
494
|
+
return yield* getClicksignSignatureRequest(options, id).pipe(Effect.repeat({
|
|
495
|
+
while: (request) => Match.value(request.state).pipe(Match.whenOr("draft", "sent", () => true), Match.whenOr("completed", "cancelled", "deleted", "declined", "expired", () => false), Match.exhaustive),
|
|
496
|
+
schedule: Schedule.spaced(interval),
|
|
497
|
+
}));
|
|
498
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signature-kit/clicksign",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Licitei/signature-kit.git"
|
|
8
|
+
},
|
|
5
9
|
"files": [
|
|
6
10
|
"dist",
|
|
7
11
|
"README.md",
|
|
@@ -22,22 +26,21 @@
|
|
|
22
26
|
"access": "public"
|
|
23
27
|
},
|
|
24
28
|
"scripts": {
|
|
25
|
-
"build": "tsc -b tsconfig.json",
|
|
26
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
29
|
"test": "vitest run"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"@signature-kit/
|
|
31
|
-
"@signature-kit/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"@signature-kit/crypto": "^0.2.1",
|
|
33
|
+
"@signature-kit/http": "^0.1.0",
|
|
34
|
+
"@signature-kit/signatures": "^0.2.0",
|
|
35
|
+
"alchemy": "2.0.0-beta.83",
|
|
36
|
+
"effect": "4.0.5"
|
|
34
37
|
},
|
|
35
38
|
"nx": {
|
|
36
39
|
"targets": {
|
|
37
40
|
"npm-pack": {
|
|
38
41
|
"executor": "nx:run-commands",
|
|
39
42
|
"options": {
|
|
40
|
-
"command": "
|
|
43
|
+
"command": "bun pm pack --dry-run",
|
|
41
44
|
"cwd": "{projectRoot}"
|
|
42
45
|
}
|
|
43
46
|
},
|