@signature-kit/clicksign 0.3.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 +22 -0
- package/README.md +25 -2
- package/dist/index.d.ts +21 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -42
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
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
|
+
|
|
3
23
|
## 0.3.0
|
|
4
24
|
|
|
5
25
|
- Clicksign now owns its document/signature-request props, attributes, state
|
|
6
26
|
schema, schema names, and retained no-op diff instead of using core
|
|
7
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.
|
|
8
30
|
- Cancel Clicksign documents with `PATCH /api/v1/documents/{key}/cancel`, matching
|
|
9
31
|
the provider API that rejected the previous `POST`.
|
|
10
32
|
- Stop fabricating signed-document download URLs; absent signed-file URLs now stay
|
package/README.md
CHANGED
|
@@ -8,11 +8,15 @@ Alchemy v2 remote-signature provider for Clicksign document creation, lookup, li
|
|
|
8
8
|
bun add @signature-kit/clicksign @signature-kit/http effect alchemy
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
`effect` and `alchemy` are direct runtime dependencies. Provide
|
|
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
|
-
- `@signature-kit/clicksign` — Clicksign request/document/signer schemas, `ClicksignSignatureRequest`, `
|
|
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
|
|
|
@@ -73,6 +77,25 @@ export const cancelRequest = (id: string) =>
|
|
|
73
77
|
cancelClicksignSignatureRequest(options, id).pipe(Effect.provide(signatureHttpClientLive));
|
|
74
78
|
```
|
|
75
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
|
+
|
|
76
99
|
## Errors and i18n
|
|
77
100
|
|
|
78
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`.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { SignatureKitError } from "@signature-kit/signatures";
|
|
|
2
2
|
import { SignatureHttpClient } from "@signature-kit/http";
|
|
3
3
|
import { Resource } from "alchemy";
|
|
4
4
|
import * as Provider from "alchemy/Provider";
|
|
5
|
-
import {
|
|
5
|
+
import { Duration, Effect, Layer, Redacted, Schema } from "effect";
|
|
6
6
|
export declare const ClicksignProviderId = "clicksign";
|
|
7
7
|
export declare const ClicksignSignatureRequestStateSchema: Schema.Literals<readonly ["draft", "sent", "completed", "cancelled", "deleted", "declined", "expired"]>;
|
|
8
8
|
export type ClicksignSignatureRequestState = (typeof ClicksignSignatureRequestStateSchema)["Type"];
|
|
@@ -24,7 +24,7 @@ export declare const ClicksignSignerSchema: Schema.Struct<{
|
|
|
24
24
|
readonly name: Schema.NonEmptyString;
|
|
25
25
|
readonly email: Schema.NonEmptyString;
|
|
26
26
|
readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
|
|
27
|
-
readonly routingOrder: Schema.optional<Schema.
|
|
27
|
+
readonly routingOrder: Schema.optional<Schema.Finite>;
|
|
28
28
|
}>;
|
|
29
29
|
export type ClicksignSigner = (typeof ClicksignSignerSchema)["Type"];
|
|
30
30
|
export declare const ClicksignSignatureRequestInputSchema: Schema.Struct<{
|
|
@@ -39,7 +39,7 @@ export declare const ClicksignSignatureRequestInputSchema: Schema.Struct<{
|
|
|
39
39
|
readonly name: Schema.NonEmptyString;
|
|
40
40
|
readonly email: Schema.NonEmptyString;
|
|
41
41
|
readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
|
|
42
|
-
readonly routingOrder: Schema.optional<Schema.
|
|
42
|
+
readonly routingOrder: Schema.optional<Schema.Finite>;
|
|
43
43
|
}>>;
|
|
44
44
|
readonly send: Schema.optional<Schema.Boolean>;
|
|
45
45
|
readonly expiresAt: Schema.optional<Schema.Date>;
|
|
@@ -58,7 +58,7 @@ export declare const ClicksignSignatureRequestPropsSchema: Schema.Struct<{
|
|
|
58
58
|
readonly name: Schema.NonEmptyString;
|
|
59
59
|
readonly email: Schema.NonEmptyString;
|
|
60
60
|
readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
|
|
61
|
-
readonly routingOrder: Schema.optional<Schema.
|
|
61
|
+
readonly routingOrder: Schema.optional<Schema.Finite>;
|
|
62
62
|
}>>;
|
|
63
63
|
readonly send: Schema.optional<Schema.Boolean>;
|
|
64
64
|
readonly expiresAt: Schema.optional<Schema.Date>;
|
|
@@ -89,25 +89,29 @@ export declare const ClicksignProviderOptionsSchema: Schema.Struct<{
|
|
|
89
89
|
export type ClicksignProviderOptions = (typeof ClicksignProviderOptionsSchema)["Type"];
|
|
90
90
|
export type ClicksignSignatureRequest = Resource<"SignatureKit.ClicksignSignatureRequest", ClicksignSignatureRequestProps, ClicksignSignatureRequestAttributes>;
|
|
91
91
|
export declare const ClicksignSignatureRequest: import("alchemy").ResourceClass<ClicksignSignatureRequest>;
|
|
92
|
-
declare const ClicksignCredentials_base: Context.ServiceClass<ClicksignCredentials, "@signature-kit/clicksign/Credentials", {
|
|
93
|
-
readonly accessToken: Redacted.Redacted<string>;
|
|
94
|
-
readonly environment?: "production" | "sandbox" | undefined;
|
|
95
|
-
readonly baseUrl?: string | undefined;
|
|
96
|
-
readonly locale?: "en-US" | "pt-BR" | undefined;
|
|
97
|
-
readonly autoClose?: boolean | undefined;
|
|
98
|
-
}>;
|
|
99
|
-
export declare class ClicksignCredentials extends ClicksignCredentials_base {
|
|
100
|
-
}
|
|
101
|
-
export declare const clicksignCredentialsLayer: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignCredentials, SignatureKitError>;
|
|
102
|
-
export declare const ClicksignSignatureRequestProvider: () => Layer.Layer<Provider.Provider<ClicksignSignatureRequest>, never, ClicksignCredentials | SignatureHttpClient>;
|
|
103
92
|
declare const ClicksignProviders_base: Provider.ProviderCollection<ClicksignProviders, "@signature-kit/clicksign/Providers">;
|
|
104
|
-
|
|
93
|
+
declare class ClicksignProviders extends ClicksignProviders_base {
|
|
105
94
|
}
|
|
106
|
-
export declare const providers: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignProviders,
|
|
95
|
+
export declare const providers: (options: ClicksignProviderOptions) => Layer.Layer<ClicksignProviders, never, SignatureHttpClient>;
|
|
107
96
|
export declare const getClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<ClicksignSignatureRequestAttributes, SignatureKitError, SignatureHttpClient>;
|
|
108
97
|
export declare const listClicksignSignatureRequests: (options: ClicksignProviderOptions) => Effect.Effect<readonly ClicksignSignatureRequestAttributes[], SignatureKitError, SignatureHttpClient>;
|
|
109
98
|
export declare const cancelClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
110
99
|
export declare const deleteClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
111
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>;
|
|
112
116
|
export {};
|
|
113
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.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8BAA8B,YAChC,wBAAwB,KAChC,MAAM,CAAC,MAAM,CACd,SAAS,mCAAmC,EAAE,EAC9C,iBAAiB,EACjB,mBAAmB,CAkBjB,CAAC;AAEL,eAAO,MAAM,+BAA+B,YACjC,wBAAwB,MAC7B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,+BAA+B,YACjC,wBAAwB,MAC7B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,+BAA+B,YACjC,wBAAwB,MAC7B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAiB/D,CAAC;AAEL,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;0CAkC3C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { bytesToBase64 } from "@signature-kit/crypto/base64";
|
|
1
|
+
import { base64ToBytes, bytesToBase64 } from "@signature-kit/crypto/base64";
|
|
2
2
|
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, redactedStringSchema, } from "@signature-kit/signatures";
|
|
3
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, Match, Option, Redacted, Schema, Stream } from "effect";
|
|
6
|
+
import { Context, Duration, Effect, Layer, Match, Option, Redacted, Schedule, Schema, Stream, } from "effect";
|
|
7
7
|
const ClicksignSchemaName = {
|
|
8
8
|
providerOptions: "ClicksignProviderOptions",
|
|
9
9
|
signatureRequestProps: "ClicksignSignatureRequestProps",
|
|
@@ -42,7 +42,7 @@ export const ClicksignSignerSchema = Schema.Struct({
|
|
|
42
42
|
name: Schema.NonEmptyString,
|
|
43
43
|
email: Schema.NonEmptyString,
|
|
44
44
|
role: Schema.optional(ClicksignSignerRoleSchema),
|
|
45
|
-
routingOrder: Schema.optional(Schema.
|
|
45
|
+
routingOrder: Schema.optional(Schema.Finite),
|
|
46
46
|
});
|
|
47
47
|
export const ClicksignSignatureRequestInputSchema = Schema.Struct({
|
|
48
48
|
title: Schema.NonEmptyString,
|
|
@@ -73,24 +73,26 @@ export const ClicksignSignatureRequestAttributesSchema = Schema.Struct({
|
|
|
73
73
|
});
|
|
74
74
|
const clicksignSignatureRequestNoopDiff = { action: "noop" };
|
|
75
75
|
const clicksignSignatureRequestDiff = ({ olds, }) => Effect.succeed(olds === undefined ? undefined : clicksignSignatureRequestNoopDiff);
|
|
76
|
-
const clicksignSignatureRequestInputFromProps = (props)
|
|
76
|
+
const clicksignSignatureRequestInputFromProps = Effect.fn(function* (props) {
|
|
77
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
|
+
];
|
|
78
86
|
return {
|
|
79
87
|
title: props.title,
|
|
80
|
-
documents
|
|
81
|
-
{
|
|
82
|
-
fileName: document.fileName,
|
|
83
|
-
mimeType: document.mimeType,
|
|
84
|
-
content: Uint8Array.fromBase64(document.contentBase64),
|
|
85
|
-
},
|
|
86
|
-
],
|
|
88
|
+
documents,
|
|
87
89
|
recipients: props.recipients,
|
|
88
90
|
...(props.message === undefined ? {} : { message: props.message }),
|
|
89
91
|
...(props.send === undefined ? {} : { send: props.send }),
|
|
90
92
|
...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
|
|
91
93
|
...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
|
|
92
94
|
};
|
|
93
|
-
};
|
|
95
|
+
});
|
|
94
96
|
const clicksignSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(ClicksignSignatureRequestPropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
95
97
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
96
98
|
retryable: false,
|
|
@@ -98,7 +100,7 @@ const clicksignSignatureRequestInputFromResourceProps = (props) => Schema.decode
|
|
|
98
100
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
99
101
|
schemaName: ClicksignSchemaName.signatureRequestProps,
|
|
100
102
|
issueMessage: String(issue),
|
|
101
|
-
})), Effect.
|
|
103
|
+
})), Effect.flatMap(clicksignSignatureRequestInputFromProps));
|
|
102
104
|
const CLICKSIGN_PROVIDER_COLLECTION_ID = "@signature-kit/clicksign/Providers";
|
|
103
105
|
const SANDBOX_BASE_URL = "https://sandbox.clicksign.com/api/v1";
|
|
104
106
|
const PRODUCTION_BASE_URL = "https://app.clicksign.com/api/v1";
|
|
@@ -131,9 +133,9 @@ const ClicksignListResultSchema = Schema.Struct({
|
|
|
131
133
|
list: Schema.Struct({ request_signature_key: Schema.NonEmptyString }),
|
|
132
134
|
});
|
|
133
135
|
const ClicksignPageInfosSchema = Schema.Struct({
|
|
134
|
-
total_pages: Schema.optional(Schema.Union([Schema.
|
|
135
|
-
current_page: Schema.optional(Schema.Union([Schema.
|
|
136
|
-
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])),
|
|
137
139
|
last_page: Schema.optional(Schema.Boolean),
|
|
138
140
|
});
|
|
139
141
|
const ClicksignDocumentsResultSchema = Schema.Struct({
|
|
@@ -199,8 +201,6 @@ const toClicksignSignatureRequestAttributes = (baseUrl, document) => {
|
|
|
199
201
|
state: toClicksignSignatureRequestAttributesState(document.status),
|
|
200
202
|
...(document.status === undefined ? {} : { providerStatus: document.status }),
|
|
201
203
|
detailsUrl: `${baseUrl}${clicksignDocumentPath(document.key)}`,
|
|
202
|
-
// Clicksign v1 has no /documents/{key}/download endpoint — signed files are
|
|
203
|
-
// only exposed through document.downloads.*_url, so absent means absent.
|
|
204
204
|
...(downloadUrl === undefined ? {} : { downloadUrl }),
|
|
205
205
|
};
|
|
206
206
|
};
|
|
@@ -230,7 +230,6 @@ const listClicksignSignatureRequestsInternal = (http, options, baseUrl) => Strea
|
|
|
230
230
|
}).pipe(Stream.runCollect);
|
|
231
231
|
const cancelClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http.requestVoid({
|
|
232
232
|
provider: PROVIDER,
|
|
233
|
-
// Clicksign v1 cancels via PATCH /api/v1/documents/{key}/cancel.
|
|
234
233
|
method: "PATCH",
|
|
235
234
|
...withAccessToken(baseUrl, `${clicksignDocumentPath(id)}/cancel`, options.accessToken),
|
|
236
235
|
});
|
|
@@ -282,8 +281,6 @@ const downloadClicksignSignedDocumentInternal = (http, options, baseUrl, id) =>
|
|
|
282
281
|
...clicksignDownloadTarget(baseUrl, signedDocumentUrl, options.accessToken),
|
|
283
282
|
});
|
|
284
283
|
}
|
|
285
|
-
// No downloads.*_url on the document yet — Clicksign only exposes the
|
|
286
|
-
// signed file once signing finishes; there is no generic download route.
|
|
287
284
|
return Effect.fail(new SignatureKitError({
|
|
288
285
|
code: SignatureKitErrorCodeValue.unsupportedOperation,
|
|
289
286
|
retryable: false,
|
|
@@ -293,16 +290,16 @@ const downloadClicksignSignedDocumentInternal = (http, options, baseUrl, id) =>
|
|
|
293
290
|
}));
|
|
294
291
|
}));
|
|
295
292
|
export const ClicksignSignatureRequest = Resource("SignatureKit.ClicksignSignatureRequest", { defaultRemovalPolicy: "retain" });
|
|
296
|
-
|
|
293
|
+
class ClicksignCredentials extends Context.Service()("@signature-kit/clicksign/Credentials") {
|
|
297
294
|
}
|
|
298
|
-
|
|
295
|
+
const clicksignCredentialsLayer = (options) => Layer.effect(ClicksignCredentials, Effect.cached(Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
299
296
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
300
297
|
retryable: false,
|
|
301
298
|
provider: PROVIDER,
|
|
302
299
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
303
300
|
schemaName: ClicksignSchemaName.providerOptions,
|
|
304
301
|
issueMessage: String(issue),
|
|
305
|
-
}))));
|
|
302
|
+
})))));
|
|
306
303
|
const clicksignBaseUrl = (options) => {
|
|
307
304
|
if (options.baseUrl !== undefined)
|
|
308
305
|
return normalizedBaseUrl(options.baseUrl);
|
|
@@ -333,9 +330,6 @@ const createDocument = (http, options, baseUrl, input, document) => http
|
|
|
333
330
|
deadline_at: input.expiresAt?.toISOString(),
|
|
334
331
|
auto_close: options.autoClose ?? true,
|
|
335
332
|
locale: options.locale ?? "pt-BR",
|
|
336
|
-
// Only serialize signing when the caller asked for an order —
|
|
337
|
-
// multiple recipients without routingOrder sign in parallel, like
|
|
338
|
-
// every other provider.
|
|
339
333
|
sequence_enabled: input.recipients.some((recipient) => recipient.routingOrder !== undefined),
|
|
340
334
|
},
|
|
341
335
|
}),
|
|
@@ -387,9 +381,7 @@ const notifyRecipient = (http, options, baseUrl, requestSignatureKey, input) =>
|
|
|
387
381
|
});
|
|
388
382
|
const createClicksignSignatureRequest = (http, options, baseUrl, input) => {
|
|
389
383
|
const [document] = input.documents;
|
|
390
|
-
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.
|
|
391
|
-
? deleteClicksignSignatureRequestInternal(http, options, baseUrl, documentKey).pipe(Effect.catch(() => Effect.void), Effect.flatMap(() => Effect.fail(error)))
|
|
392
|
-
: Effect.fail(error)), Effect.flatMap((requestSignatureKeys) => input.send === false
|
|
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
|
|
393
385
|
? Effect.succeed({ documentKey })
|
|
394
386
|
: Effect.forEach(requestSignatureKeys, (requestSignatureKey) => notifyRecipient(http, options, baseUrl, requestSignatureKey, input), { concurrency: 4, discard: true }).pipe(Effect.as({ documentKey }))))), Effect.map(({ documentKey }) => ({
|
|
395
387
|
provider: PROVIDER,
|
|
@@ -397,31 +389,38 @@ const createClicksignSignatureRequest = (http, options, baseUrl, input) => {
|
|
|
397
389
|
state: input.send === false ? "draft" : "sent",
|
|
398
390
|
})));
|
|
399
391
|
};
|
|
400
|
-
|
|
401
|
-
const
|
|
392
|
+
const clicksignSignatureRequestProvider = Provider.effect(ClicksignSignatureRequest, Effect.gen(function* () {
|
|
393
|
+
const credentials = yield* ClicksignCredentials;
|
|
402
394
|
const http = yield* SignatureHttpClient;
|
|
403
|
-
const baseUrl = clicksignBaseUrl(options);
|
|
404
395
|
return ClicksignSignatureRequest.Provider.of({
|
|
405
396
|
nuke: { skip: true },
|
|
406
397
|
diff: clicksignSignatureRequestDiff,
|
|
407
|
-
list: () =>
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
+
}),
|
|
413
406
|
reconcile: Effect.fn(function* ({ news, output }) {
|
|
414
407
|
if (output !== undefined)
|
|
415
408
|
return output;
|
|
409
|
+
const options = yield* credentials;
|
|
410
|
+
const baseUrl = clicksignBaseUrl(options);
|
|
416
411
|
const input = yield* clicksignSignatureRequestInputFromResourceProps(news);
|
|
417
412
|
return yield* createClicksignSignatureRequest(http, options, baseUrl, input);
|
|
418
413
|
}),
|
|
419
|
-
delete: ({ output })
|
|
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);
|
|
418
|
+
}),
|
|
420
419
|
});
|
|
421
420
|
}));
|
|
422
|
-
|
|
421
|
+
class ClicksignProviders extends Provider.ProviderCollection()(CLICKSIGN_PROVIDER_COLLECTION_ID) {
|
|
423
422
|
}
|
|
424
|
-
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)));
|
|
425
424
|
export const getClicksignSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
426
425
|
const valid = yield* Schema.decodeUnknownEffect(ClicksignProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
427
426
|
code: SignatureKitErrorCodeValue.invalidInput,
|
|
@@ -482,3 +481,18 @@ export const downloadClicksignSignedDocument = (options, id) => Effect.gen(funct
|
|
|
482
481
|
const http = yield* SignatureHttpClient;
|
|
483
482
|
return yield* downloadClicksignSignedDocumentInternal(http, valid, clicksignBaseUrl(valid), id);
|
|
484
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,23 +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
32
|
"@signature-kit/crypto": "^0.2.1",
|
|
31
33
|
"@signature-kit/http": "^0.1.0",
|
|
32
|
-
"@signature-kit/signatures": "^0.
|
|
33
|
-
"alchemy": "2.0.0-beta.
|
|
34
|
-
"effect": "4.0.
|
|
34
|
+
"@signature-kit/signatures": "^0.2.0",
|
|
35
|
+
"alchemy": "2.0.0-beta.83",
|
|
36
|
+
"effect": "4.0.5"
|
|
35
37
|
},
|
|
36
38
|
"nx": {
|
|
37
39
|
"targets": {
|
|
38
40
|
"npm-pack": {
|
|
39
41
|
"executor": "nx:run-commands",
|
|
40
42
|
"options": {
|
|
41
|
-
"command": "
|
|
43
|
+
"command": "bun pm pack --dry-run",
|
|
42
44
|
"cwd": "{projectRoot}"
|
|
43
45
|
}
|
|
44
46
|
},
|