@signature-kit/clicksign 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ - Clicksign now owns its document/signature-request props, attributes, state
6
+ schema, schema names, and retained no-op diff instead of using core
7
+ remote-signature contracts.
8
+ - Cancel Clicksign documents with `PATCH /api/v1/documents/{key}/cancel`, matching
9
+ the provider API that rejected the previous `POST`.
10
+ - Stop fabricating signed-document download URLs; absent signed-file URLs now stay
11
+ absent and download attempts fail as typed `unsupportedOperation` errors.
12
+ - Enable sequential signing only when at least one signer has `routingOrder`, so
13
+ unordered multi-signer requests remain parallel.
14
+ - Redact `access_token` from token-bearing signed-document diagnostic URLs, so
15
+ typed error reasons never leak provider download secrets.
16
+ - Limit create rollback deletion to unambiguous pre-effect 4xx failures (except
17
+ 408, 409, and 429); response-shape errors, 5xxs, and timeouts no longer delete
18
+ possibly live documents.
19
+ - Add offline local-HTTP-server coverage for Clicksign provider behavior in the
20
+ default test suite.
21
+
22
+ Breaking: request props now use `ClicksignSignatureRequestProps` with
23
+ `contentBase64` documents, and `getClicksignSignatureRequest` /
24
+ `listClicksignSignatureRequests` return `ClicksignSignatureRequestAttributes`
25
+ instead of core `RemoteSignature*` types.
26
+
27
+ ## 0.2.0
28
+
29
+ - Authenticate same-host signed-document downloads (previously the fallback URL was requested
30
+ without an access token and always 401'd).
31
+ - Map the `closed` terminal status to completed.
32
+ - Paginate list results.
33
+ - Make the multi-step create non-retryable after partial progress.
34
+ - Total status mapping over exact literals instead of substring matching.
35
+
3
36
  ## 0.1.0
4
37
 
5
38
  - Initial npm-ready release for `@signature-kit/clicksign`.
6
39
  - 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.
40
+ - 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,83 @@
1
1
  # @signature-kit/clicksign
2
2
 
3
- Alchemy v2 remote-signature provider for Clicksign document creation, lookup, cancellation, deletion, and signed-document download.
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
- ## Exports
11
+ `effect` and `alchemy` are direct runtime dependencies. Provide `signatureHttpClientLive` at the stack boundary; `providers(options)` supplies only Clicksign credentials and resource providers.
12
12
 
13
- - `@signature-kit/clicksign`
13
+ ## Public surface
14
14
 
15
- ## Runtime model
15
+ - `@signature-kit/clicksign` — Clicksign request/document/signer schemas, `ClicksignSignatureRequest`, `ClicksignProviders`, `providers`, `getClicksignSignatureRequest`, `listClicksignSignatureRequests`, `cancelClicksignSignatureRequest`, `deleteClicksignSignatureRequest`, and `downloadClicksignSignedDocument`.
16
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.
17
+ Capability matrix:
18
18
 
19
- ## Version
19
+ | Capability | Supported |
20
+ | ------------------------------- | -------------------------------------------------- |
21
+ | Create retained Alchemy request | Yes |
22
+ | Get request | Yes |
23
+ | List requests | Yes |
24
+ | Cancel request | Yes, via `PATCH /documents/{key}/cancel` |
25
+ | Delete request | Yes |
26
+ | Download signed document | Yes, only when Clicksign exposes a signed-file URL |
20
27
 
21
- Current npm release line: `0.1.0`.
28
+ 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.
29
+
30
+ ## Example
31
+
32
+ ```ts
33
+ import * as Alchemy from "alchemy";
34
+ import {
35
+ ClicksignSignatureRequest,
36
+ cancelClicksignSignatureRequest,
37
+ providers as clicksignProviders,
38
+ type ClicksignProviderOptions,
39
+ } from "@signature-kit/clicksign";
40
+ import { signatureHttpClientLive } from "@signature-kit/http";
41
+ import { Effect, Layer, Redacted } from "effect";
42
+
43
+ declare const pdfBase64: string;
44
+ declare const accessToken: string;
45
+
46
+ const options: ClicksignProviderOptions = {
47
+ accessToken: Redacted.make(accessToken),
48
+ environment: "sandbox",
49
+ locale: "pt-BR",
50
+ autoClose: true,
51
+ };
52
+
53
+ export default class Contracts extends Alchemy.Stack<Contracts>()(
54
+ "Contracts",
55
+ {
56
+ providers: Layer.merge(clicksignProviders(options), signatureHttpClientLive),
57
+ state: Alchemy.inMemoryState(),
58
+ },
59
+ Effect.gen(function* () {
60
+ return yield* ClicksignSignatureRequest("service-agreement", {
61
+ title: "Service agreement",
62
+ message: "Review and sign this document.",
63
+ documents: [
64
+ { fileName: "contract.pdf", mimeType: "application/pdf", contentBase64: pdfBase64 },
65
+ ],
66
+ recipients: [{ name: "Ada Lovelace", email: "ada@example.com", role: "signer" }],
67
+ send: true,
68
+ });
69
+ }),
70
+ ) {}
71
+
72
+ export const cancelRequest = (id: string) =>
73
+ cancelClicksignSignatureRequest(options, id).pipe(Effect.provide(signatureHttpClientLive));
74
+ ```
75
+
76
+ ## Errors and i18n
77
+
78
+ 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`.
79
+
80
+ Docs: <https://signaturekit.dev/en-US/docs/providers/clicksign>.
22
81
 
23
82
  ## License
24
83
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,80 @@
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";
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
5
  import { Context, 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.Number>;
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.Number>;
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.Number>;
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,7 +87,7 @@ 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", RemoteSignatureRequestProps, RemoteSignatureRequest>;
90
+ export type ClicksignSignatureRequest = Resource<"SignatureKit.ClicksignSignatureRequest", ClicksignSignatureRequestProps, ClicksignSignatureRequestAttributes>;
20
91
  export declare const ClicksignSignatureRequest: import("alchemy").ResourceClass<ClicksignSignatureRequest>;
21
92
  declare const ClicksignCredentials_base: Context.ServiceClass<ClicksignCredentials, "@signature-kit/clicksign/Credentials", {
22
93
  readonly accessToken: Redacted.Redacted<string>;
@@ -33,8 +104,8 @@ declare const ClicksignProviders_base: Provider.ProviderCollection<ClicksignProv
33
104
  export declare class ClicksignProviders extends ClicksignProviders_base {
34
105
  }
35
106
  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>;
107
+ export declare const getClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<ClicksignSignatureRequestAttributes, SignatureKitError, SignatureHttpClient>;
108
+ export declare const listClicksignSignatureRequests: (options: ClicksignProviderOptions) => Effect.Effect<readonly ClicksignSignatureRequestAttributes[], SignatureKitError, SignatureHttpClient>;
38
109
  export declare const cancelClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
39
110
  export declare const deleteClicksignSignatureRequest: (options: ClicksignProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
40
111
  export declare const downloadClicksignSignedDocument: (options: ClicksignProviderOptions, id: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
@@ -1 +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,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C,MAAM,CAAC,mCAAmC,EAAE,iBAAiB,EAAE,mBAAmB,CAiBxF,CAAC;AAEL,eAAO,MAAM,8BAA8B,GACzC,SAAS,wBAAwB,KAChC,MAAM,CAAC,MAAM,CACd,SAAS,mCAAmC,EAAE,EAC9C,iBAAiB,EACjB,mBAAmB,CAkBjB,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 CHANGED
@@ -1,10 +1,104 @@
1
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";
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 PROVIDER = "clicksign";
6
+ import { Context, Effect, Layer, Match, Option, Redacted, 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.Number),
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 = (props) => {
77
+ const [document] = props.documents;
78
+ return {
79
+ title: props.title,
80
+ documents: [
81
+ {
82
+ fileName: document.fileName,
83
+ mimeType: document.mimeType,
84
+ content: Uint8Array.fromBase64(document.contentBase64),
85
+ },
86
+ ],
87
+ recipients: props.recipients,
88
+ ...(props.message === undefined ? {} : { message: props.message }),
89
+ ...(props.send === undefined ? {} : { send: props.send }),
90
+ ...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
91
+ ...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
92
+ };
93
+ };
94
+ const clicksignSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(ClicksignSignatureRequestPropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
95
+ code: SignatureKitErrorCodeValue.invalidInput,
96
+ retryable: false,
97
+ provider: PROVIDER,
98
+ operation: SignatureKitOperationValue.schemaDecode,
99
+ schemaName: ClicksignSchemaName.signatureRequestProps,
100
+ issueMessage: String(issue),
101
+ })), Effect.map(clicksignSignatureRequestInputFromProps));
8
102
  const CLICKSIGN_PROVIDER_COLLECTION_ID = "@signature-kit/clicksign/Providers";
9
103
  const SANDBOX_BASE_URL = "https://sandbox.clicksign.com/api/v1";
10
104
  const PRODUCTION_BASE_URL = "https://app.clicksign.com/api/v1";
@@ -17,11 +111,18 @@ export const ClicksignProviderOptionsSchema = Schema.Struct({
17
111
  locale: Schema.optional(ClicksignLocaleSchema),
18
112
  autoClose: Schema.optional(Schema.Boolean),
19
113
  });
114
+ const ClicksignDocumentDownloadsSchema = Schema.Struct({
115
+ signed_file_url: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
116
+ });
117
+ const ClicksignDocumentSchema = Schema.Struct({
118
+ key: Schema.NonEmptyString,
119
+ status: Schema.optional(Schema.String),
120
+ download_url: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
121
+ downloadUrl: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
122
+ downloads: Schema.optional(ClicksignDocumentDownloadsSchema),
123
+ });
20
124
  const ClicksignDocumentResultSchema = Schema.Struct({
21
- document: Schema.Struct({
22
- key: Schema.NonEmptyString,
23
- status: Schema.optional(Schema.String),
24
- }),
125
+ document: ClicksignDocumentSchema,
25
126
  });
26
127
  const ClicksignSignerResultSchema = Schema.Struct({
27
128
  signer: Schema.Struct({ key: Schema.NonEmptyString }),
@@ -29,95 +130,167 @@ const ClicksignSignerResultSchema = Schema.Struct({
29
130
  const ClicksignListResultSchema = Schema.Struct({
30
131
  list: Schema.Struct({ request_signature_key: Schema.NonEmptyString }),
31
132
  });
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,
133
+ const ClicksignPageInfosSchema = Schema.Struct({
134
+ total_pages: Schema.optional(Schema.Union([Schema.Number, Schema.String])),
135
+ current_page: Schema.optional(Schema.Union([Schema.Number, Schema.String])),
136
+ next_page: Schema.optional(Schema.Union([Schema.Number, Schema.String, Schema.Null])),
137
+ last_page: Schema.optional(Schema.Boolean),
40
138
  });
41
139
  const ClicksignDocumentsResultSchema = Schema.Struct({
42
140
  documents: Schema.Array(ClicksignDocumentSchema),
141
+ page_infos: Schema.optional(ClicksignPageInfosSchema),
43
142
  });
44
- const toRemoteSignatureRequestState = (status) => {
143
+ const clicksignPathId = (id) => encodeURIComponent(id);
144
+ const clicksignDocumentPath = (id) => `/documents/${clicksignPathId(id)}`;
145
+ const ClicksignStatusSchema = Schema.Literals([
146
+ "draft",
147
+ "completed",
148
+ "signed",
149
+ "closed",
150
+ "cancelled",
151
+ "canceled",
152
+ "deleted",
153
+ "declined",
154
+ "expired",
155
+ ]);
156
+ const isClicksignStatus = Schema.is(ClicksignStatusSchema);
157
+ const toClicksignSignatureRequestAttributesState = (status) => {
45
158
  if (status === undefined)
46
159
  return "sent";
47
160
  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";
161
+ if (!isClicksignStatus(normalized))
162
+ return "sent";
163
+ 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"));
164
+ };
165
+ const resolveClicksignSignedDocumentUrl = (document) => {
166
+ const signedFile = document.downloads?.signed_file_url;
167
+ if (typeof signedFile === "string" && signedFile.length > 0)
168
+ return signedFile;
169
+ if (typeof document.download_url === "string" && document.download_url.length > 0)
170
+ return document.download_url;
171
+ if (typeof document.downloadUrl === "string" && document.downloadUrl.length > 0)
172
+ return document.downloadUrl;
173
+ return undefined;
174
+ };
175
+ const parseClicksignPageNumber = (value) => {
176
+ if (typeof value !== "string" && typeof value !== "number")
177
+ return undefined;
178
+ const parsed = Number.parseInt(String(value), 10);
179
+ return Number.isNaN(parsed) || parsed <= 0 ? undefined : parsed;
180
+ };
181
+ const clicksignListNextPage = (pageInfos, currentPage) => {
182
+ if (pageInfos === undefined)
183
+ return;
184
+ const nextPage = parseClicksignPageNumber(pageInfos.next_page);
185
+ if (nextPage !== undefined && nextPage > currentPage)
186
+ return nextPage;
187
+ if (pageInfos.last_page === true)
188
+ return undefined;
189
+ if (pageInfos.last_page === false)
190
+ return currentPage + 1;
191
+ const totalPages = parseClicksignPageNumber(pageInfos.total_pages);
192
+ return totalPages === undefined || totalPages <= currentPage ? undefined : currentPage + 1;
193
+ };
194
+ const toClicksignSignatureRequestAttributes = (baseUrl, document) => {
195
+ const downloadUrl = resolveClicksignSignedDocumentUrl(document);
196
+ return {
197
+ provider: PROVIDER,
198
+ id: document.key,
199
+ state: toClicksignSignatureRequestAttributesState(document.status),
200
+ ...(document.status === undefined ? {} : { providerStatus: document.status }),
201
+ 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
+ ...(downloadUrl === undefined ? {} : { downloadUrl }),
205
+ };
61
206
  };
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
207
  const getClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http
73
208
  .requestJson({
74
209
  provider: PROVIDER,
75
210
  method: "GET",
76
- ...withAccessToken(baseUrl, `/documents/${id}`, options.accessToken),
211
+ ...withAccessToken(baseUrl, clicksignDocumentPath(id), options.accessToken),
77
212
  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))));
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);
87
231
  const cancelClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http.requestVoid({
88
232
  provider: PROVIDER,
89
- method: "POST",
90
- ...withAccessToken(baseUrl, `/documents/${id}/cancel`, options.accessToken),
233
+ // Clicksign v1 cancels via PATCH /api/v1/documents/{key}/cancel.
234
+ method: "PATCH",
235
+ ...withAccessToken(baseUrl, `${clicksignDocumentPath(id)}/cancel`, options.accessToken),
91
236
  });
92
237
  const deleteClicksignSignatureRequestInternal = (http, options, baseUrl, id) => http
93
238
  .requestVoid({
94
239
  provider: PROVIDER,
95
240
  method: "DELETE",
96
- ...withAccessToken(baseUrl, `/documents/${id}`, options.accessToken),
241
+ ...withAccessToken(baseUrl, clicksignDocumentPath(id), options.accessToken),
97
242
  })
98
243
  .pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.void));
244
+ const shouldRollbackClicksignCreate = (error) => error.code === SignatureKitErrorCodeValue.http &&
245
+ error.status !== undefined &&
246
+ error.status >= 400 &&
247
+ error.status < 500 &&
248
+ error.status !== 408 &&
249
+ error.status !== 409 &&
250
+ error.status !== 429;
251
+ const isAbsoluteHttpUrl = (value) => value.startsWith("http://") || value.startsWith("https://");
252
+ const clicksignDownloadPath = (path) => (path.startsWith("/") ? path : `/${path}`);
253
+ const isClicksignDownloadHost = (baseUrl, downloadUrl) => {
254
+ if (!URL.canParse(downloadUrl) || !URL.canParse(baseUrl))
255
+ return false;
256
+ return new URL(downloadUrl).host === new URL(baseUrl).host;
257
+ };
258
+ const clicksignDownloadTarget = (baseUrl, downloadUrl, accessToken) => {
259
+ if (!isAbsoluteHttpUrl(downloadUrl)) {
260
+ return withAccessToken(baseUrl, clicksignDownloadPath(downloadUrl), accessToken);
261
+ }
262
+ if (!isClicksignDownloadHost(baseUrl, downloadUrl))
263
+ return { url: downloadUrl };
264
+ const parsed = new URL(downloadUrl);
265
+ if (parsed.searchParams.has("access_token")) {
266
+ const diagnosticUrl = new URL(downloadUrl);
267
+ diagnosticUrl.searchParams.set("access_token", "<redacted>");
268
+ return { url: downloadUrl, diagnosticUrl: diagnosticUrl.toString() };
269
+ }
270
+ const targetUrl = new URL(downloadUrl);
271
+ const diagnosticUrl = new URL(downloadUrl);
272
+ targetUrl.searchParams.set("access_token", Redacted.value(accessToken));
273
+ diagnosticUrl.searchParams.set("access_token", "<redacted>");
274
+ return { url: targetUrl.toString(), diagnosticUrl: diagnosticUrl.toString() };
275
+ };
99
276
  const downloadClicksignSignedDocumentInternal = (http, options, baseUrl, id) => getClicksignSignatureRequestInternal(http, options, baseUrl, id).pipe(Effect.flatMap((request) => {
100
277
  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
278
  if (signedDocumentUrl !== undefined) {
110
279
  return http.requestBytes({
111
280
  provider: PROVIDER,
112
281
  method: "GET",
113
- ...withAccessToken(baseUrl, signedDocumentUrl.startsWith("/") ? signedDocumentUrl : `/${signedDocumentUrl}`, options.accessToken),
282
+ ...clicksignDownloadTarget(baseUrl, signedDocumentUrl, options.accessToken),
114
283
  });
115
284
  }
116
- return http.requestBytes({
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
+ return Effect.fail(new SignatureKitError({
288
+ code: SignatureKitErrorCodeValue.unsupportedOperation,
289
+ retryable: false,
117
290
  provider: PROVIDER,
118
- method: "GET",
119
- ...withAccessToken(baseUrl, `/documents/${id}/download`, options.accessToken),
120
- });
291
+ operation: ClicksignOperation.download,
292
+ reason: `Clicksign document ${id} has no signed file to download yet (status: ${request.providerStatus ?? "unknown"}).`,
293
+ }));
121
294
  }));
122
295
  export const ClicksignSignatureRequest = Resource("SignatureKit.ClicksignSignatureRequest", { defaultRemovalPolicy: "retain" });
123
296
  export class ClicksignCredentials extends Context.Service()("@signature-kit/clicksign/Credentials") {
@@ -127,7 +300,7 @@ export const clicksignCredentialsLayer = (options) => Layer.effect(ClicksignCred
127
300
  retryable: false,
128
301
  provider: PROVIDER,
129
302
  operation: SignatureKitOperationValue.schemaDecode,
130
- schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
303
+ schemaName: ClicksignSchemaName.providerOptions,
131
304
  issueMessage: String(issue),
132
305
  }))));
133
306
  const clicksignBaseUrl = (options) => {
@@ -160,11 +333,13 @@ const createDocument = (http, options, baseUrl, input, document) => http
160
333
  deadline_at: input.expiresAt?.toISOString(),
161
334
  auto_close: options.autoClose ?? true,
162
335
  locale: options.locale ?? "pt-BR",
163
- sequence_enabled: input.recipients.length > 1 ||
164
- input.recipients.some((recipient) => recipient.routingOrder !== undefined),
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
+ sequence_enabled: input.recipients.some((recipient) => recipient.routingOrder !== undefined),
165
340
  },
166
341
  }),
167
- }, ClicksignDocumentResultSchema, SignatureKitSchemaNameValue.clicksignDocumentResult)
342
+ }, ClicksignDocumentResultSchema, ClicksignSchemaName.documentResult)
168
343
  .pipe(Effect.map((result) => result.document.key));
169
344
  const createSigner = (http, options, baseUrl, recipient) => http
170
345
  .requestJson({
@@ -180,7 +355,7 @@ const createSigner = (http, options, baseUrl, recipient) => http
180
355
  has_documentation: false,
181
356
  },
182
357
  }),
183
- }, ClicksignSignerResultSchema, SignatureKitSchemaNameValue.clicksignSignerResult)
358
+ }, ClicksignSignerResultSchema, ClicksignSchemaName.signerResult)
184
359
  .pipe(Effect.map((result) => result.signer.key));
185
360
  const linkRecipient = (http, options, baseUrl, documentKey, signerKey, recipient, index, message) => http
186
361
  .requestJson({
@@ -197,7 +372,7 @@ const linkRecipient = (http, options, baseUrl, documentKey, signerKey, recipient
197
372
  message,
198
373
  },
199
374
  }),
200
- }, ClicksignListResultSchema, SignatureKitSchemaNameValue.clicksignListResult)
375
+ }, ClicksignListResultSchema, ClicksignSchemaName.listResult)
201
376
  .pipe(Effect.map((result) => result.list.request_signature_key));
202
377
  const notifyRecipient = (http, options, baseUrl, requestSignatureKey, input) => http.requestVoid({
203
378
  provider: PROVIDER,
@@ -210,20 +385,13 @@ const notifyRecipient = (http, options, baseUrl, requestSignatureKey, input) =>
210
385
  url: input.redirectUrl,
211
386
  }),
212
387
  });
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
388
+ const createClicksignSignatureRequest = (http, options, baseUrl, input) => {
389
+ 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.catch((error) => shouldRollbackClicksignCreate(error)
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
225
393
  ? Effect.succeed({ documentKey })
226
- : Effect.forEach(requestSignatureKeys, (requestSignatureKey) => notifyRecipient(http, options, baseUrl, requestSignatureKey, input), { discard: true }).pipe(Effect.as({ documentKey }))), Effect.map(({ documentKey }) => ({
394
+ : Effect.forEach(requestSignatureKeys, (requestSignatureKey) => notifyRecipient(http, options, baseUrl, requestSignatureKey, input), { concurrency: 4, discard: true }).pipe(Effect.as({ documentKey }))))), Effect.map(({ documentKey }) => ({
227
395
  provider: PROVIDER,
228
396
  id: documentKey,
229
397
  state: input.send === false ? "draft" : "sent",
@@ -234,16 +402,19 @@ export const ClicksignSignatureRequestProvider = () => Provider.effect(Clicksign
234
402
  const http = yield* SignatureHttpClient;
235
403
  const baseUrl = clicksignBaseUrl(options);
236
404
  return ClicksignSignatureRequest.Provider.of({
237
- diff: ({ olds }) => Effect.succeed(olds === undefined ? undefined : { action: "noop" }),
238
- list: () => listClicksignSignatureRequestsInternal(http, options, baseUrl),
405
+ nuke: { skip: true },
406
+ diff: clicksignSignatureRequestDiff,
407
+ list: () =>
408
+ // Retained resources must not feed account-wide nuke enumeration.
409
+ Effect.succeed([]),
239
410
  read: ({ output }) => output === undefined
240
411
  ? Effect.succeed(undefined)
241
412
  : getClicksignSignatureRequestInternal(http, options, baseUrl, output.id).pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined))),
242
413
  reconcile: Effect.fn(function* ({ news, output }) {
243
414
  if (output !== undefined)
244
415
  return output;
245
- const input = yield* remoteSignatureInputFromResourceProps(PROVIDER, news);
246
- return yield* createRemoteRequest(http, options, baseUrl, input);
416
+ const input = yield* clicksignSignatureRequestInputFromResourceProps(news);
417
+ return yield* createClicksignSignatureRequest(http, options, baseUrl, input);
247
418
  }),
248
419
  delete: ({ output }) => deleteClicksignSignatureRequestInternal(http, options, baseUrl, output.id),
249
420
  });
@@ -257,7 +428,7 @@ export const getClicksignSignatureRequest = (options, id) => Effect.gen(function
257
428
  retryable: false,
258
429
  provider: PROVIDER,
259
430
  operation: SignatureKitOperationValue.schemaDecode,
260
- schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
431
+ schemaName: ClicksignSchemaName.providerOptions,
261
432
  issueMessage: String(issue),
262
433
  })));
263
434
  const http = yield* SignatureHttpClient;
@@ -269,7 +440,7 @@ export const listClicksignSignatureRequests = (options) => Effect.gen(function*
269
440
  retryable: false,
270
441
  provider: PROVIDER,
271
442
  operation: SignatureKitOperationValue.schemaDecode,
272
- schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
443
+ schemaName: ClicksignSchemaName.providerOptions,
273
444
  issueMessage: String(issue),
274
445
  })));
275
446
  const http = yield* SignatureHttpClient;
@@ -281,7 +452,7 @@ export const cancelClicksignSignatureRequest = (options, id) => Effect.gen(funct
281
452
  retryable: false,
282
453
  provider: PROVIDER,
283
454
  operation: SignatureKitOperationValue.schemaDecode,
284
- schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
455
+ schemaName: ClicksignSchemaName.providerOptions,
285
456
  issueMessage: String(issue),
286
457
  })));
287
458
  const http = yield* SignatureHttpClient;
@@ -293,7 +464,7 @@ export const deleteClicksignSignatureRequest = (options, id) => Effect.gen(funct
293
464
  retryable: false,
294
465
  provider: PROVIDER,
295
466
  operation: SignatureKitOperationValue.schemaDecode,
296
- schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
467
+ schemaName: ClicksignSchemaName.providerOptions,
297
468
  issueMessage: String(issue),
298
469
  })));
299
470
  const http = yield* SignatureHttpClient;
@@ -305,7 +476,7 @@ export const downloadClicksignSignedDocument = (options, id) => Effect.gen(funct
305
476
  retryable: false,
306
477
  provider: PROVIDER,
307
478
  operation: SignatureKitOperationValue.schemaDecode,
308
- schemaName: SignatureKitSchemaNameValue.clicksignProviderOptions,
479
+ schemaName: ClicksignSchemaName.providerOptions,
309
480
  issueMessage: String(issue),
310
481
  })));
311
482
  const http = yield* SignatureHttpClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signature-kit/clicksign",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -27,8 +27,9 @@
27
27
  "test": "vitest run"
28
28
  },
29
29
  "dependencies": {
30
- "@signature-kit/core": "^0.1.0",
31
- "@signature-kit/crypto": "^0.1.0",
30
+ "@signature-kit/crypto": "^0.2.1",
31
+ "@signature-kit/http": "^0.1.0",
32
+ "@signature-kit/signatures": "^0.1.0",
32
33
  "alchemy": "2.0.0-beta.57",
33
34
  "effect": "4.0.0-beta.86"
34
35
  },