@signature-kit/documenso 0.3.0 → 0.4.1

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,9 +1,39 @@
1
+ ## @signature-kit/documenso@0.4.1
2
+
3
+ ### Publish the worker signing runtime
4
+
5
+ Publish `@signature-kit/signatures/session`, which `@signature-kit/react` 0.1.2 imports to sign A1 documents in a Domain RPC worker. Without it, bundlers fail to resolve the react worker entry.
6
+
7
+ A1 signing makes the WebCrypto sign step uninterruptible. CMS builds the signing-certificate-v2 attribute directly with asn1js. All packages move to Effect 4.1.0 so applications load a single Effect runtime.
8
+
9
+ ## @signature-kit/documenso@0.4.0
10
+
11
+ ### Runtime updates and signature inspection
12
+
13
+ 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.
14
+
15
+ 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.
16
+
17
+ 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.
18
+
19
+ 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.
20
+
21
+ 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.
22
+
23
+ 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.
24
+
1
25
  # Changelog
2
26
 
27
+ ## Unreleased
28
+
29
+ - Keep concrete credentials, provider, and provider-collection wiring private; consumers compose `DocumensoSignatureRequest` through `providers(options)`.
30
+
3
31
  ## 0.3.0
4
32
 
5
33
  - Documenso now owns its envelope props, attributes, state schema, schema names,
6
34
  and retained no-op diff instead of using core remote-signature contracts.
35
+ - Decode provider options through a cached credential Effect, so retained-resource
36
+ `list` hooks and `read` calls without cached output do not touch credentials.
7
37
  - Treat failed envelope distribution as still `draft` with `not_distributed`
8
38
  provider status instead of reporting it as sent.
9
39
  - Limit distribute rollback deletion to unambiguous pre-effect 4xx failures
package/README.md CHANGED
@@ -8,11 +8,15 @@ Alchemy v2 remote-signature provider for Documenso envelope creation, lookup, li
8
8
  bun add @signature-kit/documenso @signature-kit/http effect alchemy
9
9
  ```
10
10
 
11
- `effect` and `alchemy` are direct runtime dependencies. Provide `signatureHttpClientLive` at the stack boundary; `providers(options)` supplies only Documenso credentials and resource providers.
11
+ `effect` and `alchemy` are direct runtime dependencies. Provide
12
+ `signatureHttpClientLive` at the stack boundary; `providers(options)` supplies
13
+ only Documenso 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/documenso` — Documenso envelope/document/recipient schemas, `DocumensoSignatureRequest`, `DocumensoProviders`, `providers`, `getDocumensoSignatureRequest`, `listDocumensoSignatureRequests`, `cancelDocumensoSignatureRequest`, `deleteDocumensoSignatureRequest`, and `downloadDocumensoSignedDocument`.
19
+ - `@signature-kit/documenso` — Documenso envelope/document/recipient schemas, `DocumensoSignatureRequest`, `providers`, `getDocumensoSignatureRequest`, `listDocumensoSignatureRequests`, `cancelDocumensoSignatureRequest`, `deleteDocumensoSignatureRequest`, and `downloadDocumensoSignedDocument`.
16
20
 
17
21
  Capability matrix:
18
22
 
@@ -71,6 +75,25 @@ export const downloadSigned = (envelopeId: string) =>
71
75
  );
72
76
  ```
73
77
 
78
+ ## Wait for a final state
79
+
80
+ `waitForDocumensoSignatureRequest(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:
81
+
82
+ ```ts
83
+ import { waitForDocumensoSignatureRequest } from "@signature-kit/documenso";
84
+ import { signatureHttpClientLive } from "@signature-kit/http";
85
+ import { Duration, Effect } from "effect";
86
+ import type { DocumensoProviderOptions } from "@signature-kit/documenso";
87
+
88
+ declare const options: DocumensoProviderOptions;
89
+ declare const requestId: string;
90
+
91
+ const program = waitForDocumensoSignatureRequest(options, requestId, Duration.seconds(2)).pipe(
92
+ Effect.timeout(Duration.minutes(5)),
93
+ Effect.provide(signatureHttpClientLive),
94
+ );
95
+ ```
96
+
74
97
  ## Errors and i18n
75
98
 
76
99
  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,19 +2,19 @@ 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 { Context, Effect, Layer, Redacted, Schema } from "effect";
5
+ import { Duration, Effect, Layer, Redacted, Schema } from "effect";
6
6
  export declare const DocumensoProviderId = "documenso";
7
7
  export declare const DocumensoEnvelopeStateSchema: Schema.Literals<readonly ["draft", "sent", "completed", "cancelled", "deleted", "declined", "expired"]>;
8
8
  export type DocumensoEnvelopeState = (typeof DocumensoEnvelopeStateSchema)["Type"];
9
9
  export declare const DocumensoEnvelopeDocumentSchema: Schema.Struct<{
10
10
  readonly fileName: Schema.NonEmptyString;
11
- readonly mimeType: Schema.NonEmptyString;
11
+ readonly mimeType: Schema.Literal<"application/pdf">;
12
12
  readonly content: Schema.Uint8Array;
13
13
  }>;
14
14
  export type DocumensoEnvelopeDocument = (typeof DocumensoEnvelopeDocumentSchema)["Type"];
15
15
  export declare const DocumensoEnvelopeDocumentPropsSchema: Schema.Struct<{
16
16
  readonly fileName: Schema.NonEmptyString;
17
- readonly mimeType: Schema.NonEmptyString;
17
+ readonly mimeType: Schema.Literal<"application/pdf">;
18
18
  readonly contentBase64: Schema.ConstraintDecoder<string, never>;
19
19
  }>;
20
20
  export type DocumensoEnvelopeDocumentProps = (typeof DocumensoEnvelopeDocumentPropsSchema)["Type"];
@@ -24,7 +24,7 @@ export declare const DocumensoEnvelopeRecipientSchema: 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.Number>;
27
+ readonly routingOrder: Schema.optional<Schema.Finite>;
28
28
  }>;
29
29
  export type DocumensoEnvelopeRecipient = (typeof DocumensoEnvelopeRecipientSchema)["Type"];
30
30
  export declare const DocumensoEnvelopeInputSchema: Schema.Struct<{
@@ -33,14 +33,14 @@ export declare const DocumensoEnvelopeInputSchema: Schema.Struct<{
33
33
  readonly message: Schema.optional<Schema.NonEmptyString>;
34
34
  readonly documents: Schema.NonEmptyArray<Schema.Struct<{
35
35
  readonly fileName: Schema.NonEmptyString;
36
- readonly mimeType: Schema.NonEmptyString;
36
+ readonly mimeType: Schema.Literal<"application/pdf">;
37
37
  readonly content: Schema.Uint8Array;
38
38
  }>>;
39
39
  readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
40
40
  readonly name: Schema.NonEmptyString;
41
41
  readonly email: Schema.NonEmptyString;
42
42
  readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
43
- readonly routingOrder: Schema.optional<Schema.Number>;
43
+ readonly routingOrder: Schema.optional<Schema.Finite>;
44
44
  }>>;
45
45
  readonly send: Schema.optional<Schema.Boolean>;
46
46
  readonly expiresAt: Schema.optional<Schema.Date>;
@@ -53,14 +53,14 @@ export declare const DocumensoEnvelopePropsSchema: Schema.Struct<{
53
53
  readonly message: Schema.optional<Schema.NonEmptyString>;
54
54
  readonly documents: Schema.NonEmptyArray<Schema.Struct<{
55
55
  readonly fileName: Schema.NonEmptyString;
56
- readonly mimeType: Schema.NonEmptyString;
56
+ readonly mimeType: Schema.Literal<"application/pdf">;
57
57
  readonly contentBase64: Schema.ConstraintDecoder<string, never>;
58
58
  }>>;
59
59
  readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
60
60
  readonly name: Schema.NonEmptyString;
61
61
  readonly email: Schema.NonEmptyString;
62
62
  readonly role: Schema.optional<Schema.Literals<readonly ["approver", "signer"]>>;
63
- readonly routingOrder: Schema.optional<Schema.Number>;
63
+ readonly routingOrder: Schema.optional<Schema.Finite>;
64
64
  }>>;
65
65
  readonly send: Schema.optional<Schema.Boolean>;
66
66
  readonly expiresAt: Schema.optional<Schema.Date>;
@@ -87,23 +87,27 @@ export declare const DocumensoProviderOptionsSchema: Schema.Struct<{
87
87
  export type DocumensoProviderOptions = (typeof DocumensoProviderOptionsSchema)["Type"];
88
88
  export type DocumensoSignatureRequest = Resource<"SignatureKit.DocumensoSignatureRequest", DocumensoEnvelopeProps, DocumensoEnvelope>;
89
89
  export declare const DocumensoSignatureRequest: import("alchemy").ResourceClass<DocumensoSignatureRequest>;
90
- declare const DocumensoCredentials_base: Context.ServiceClass<DocumensoCredentials, "@signature-kit/documenso/Credentials", {
91
- readonly apiKey: Redacted.Redacted<string>;
92
- readonly baseUrl?: string | undefined;
93
- readonly authorizationScheme?: "raw" | "bearer" | undefined;
94
- }>;
95
- export declare class DocumensoCredentials extends DocumensoCredentials_base {
96
- }
97
- export declare const documensoCredentialsLayer: (options: DocumensoProviderOptions) => Layer.Layer<DocumensoCredentials, SignatureKitError>;
98
- export declare const DocumensoSignatureRequestProvider: () => Layer.Layer<Provider.Provider<DocumensoSignatureRequest>, never, DocumensoCredentials | SignatureHttpClient>;
99
90
  declare const DocumensoProviders_base: Provider.ProviderCollection<DocumensoProviders, "@signature-kit/documenso/Providers">;
100
- export declare class DocumensoProviders extends DocumensoProviders_base {
91
+ declare class DocumensoProviders extends DocumensoProviders_base {
101
92
  }
102
- export declare const providers: (options: DocumensoProviderOptions) => Layer.Layer<DocumensoProviders, SignatureKitError, SignatureHttpClient>;
93
+ export declare const providers: (options: DocumensoProviderOptions) => Layer.Layer<DocumensoProviders, never, SignatureHttpClient>;
103
94
  export declare const getDocumensoSignatureRequest: (options: DocumensoProviderOptions, id: string) => Effect.Effect<DocumensoEnvelope, SignatureKitError, SignatureHttpClient>;
104
95
  export declare const listDocumensoSignatureRequests: (options: DocumensoProviderOptions) => Effect.Effect<ReadonlyArray<DocumensoEnvelope>, SignatureKitError, SignatureHttpClient>;
105
96
  export declare const cancelDocumensoSignatureRequest: (options: DocumensoProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
106
97
  export declare const deleteDocumensoSignatureRequest: (options: DocumensoProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
107
98
  export declare const downloadDocumensoSignedDocument: (options: DocumensoProviderOptions, envelopeId: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
99
+ export declare const waitForDocumensoSignatureRequest: (options: {
100
+ readonly apiKey: Redacted.Redacted<string>;
101
+ readonly baseUrl?: string | undefined;
102
+ readonly authorizationScheme?: "bearer" | "raw" | undefined;
103
+ }, id: string, pollInterval: Duration.Duration) => Effect.Effect<{
104
+ readonly provider: "documenso";
105
+ readonly id: string;
106
+ readonly state: "cancelled" | "completed" | "declined" | "deleted" | "draft" | "expired" | "sent";
107
+ readonly providerStatus?: string | undefined;
108
+ readonly signingUrl?: string | undefined;
109
+ readonly detailsUrl?: string | undefined;
110
+ readonly downloadUrl?: string | undefined;
111
+ }, SignatureKitError, SignatureHttpClient>;
108
112
  export {};
109
113
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAIlB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAqB,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAiB,QAAQ,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAkBzF,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAG/C,eAAO,MAAM,4BAA4B,yGAQvC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,eAAO,MAAM,+BAA+B;;;;EAI1C,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,+BAA+B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzF,eAAO,MAAM,oCAAoC;;;;EAI/C,CAAC;AACH,MAAM,MAAM,8BAA8B,GAAG,CAAC,OAAO,oCAAoC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnG,eAAO,MAAM,4BAA4B,kDAA0C,CAAC;AACpF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,eAAO,MAAM,gCAAgC;;;;;EAK3C,CAAC;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,gCAAgC,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3F,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;EASv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AAO,MAAM,SAAS,YAAa,wBAAwB,gEAIxD,CAAC;AAEJ,eAAO,MAAM,4BAA4B,YAC9B,wBAAwB,MAC7B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,CAiBtE,CAAC;AAEL,eAAO,MAAM,8BAA8B,YAChC,wBAAwB,KAChC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,mBAAmB,CAiBrF,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,cACrB,MAAM,KACjB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAiB/D,CAAC;AAEL,eAAO,MAAM,gCAAgC;;;;;;;;;;;;0CAkC3C,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
+ import { base64ToBytes } from "@signature-kit/crypto/base64";
1
2
  import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, redactedStringSchema, } from "@signature-kit/signatures";
2
3
  import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/http";
3
4
  import { Resource } from "alchemy";
4
5
  import * as Provider from "alchemy/Provider";
5
- 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";
6
7
  const DocumensoSchemaName = {
7
8
  providerOptions: "DocumensoProviderOptions",
8
9
  signatureRequestProps: "DocumensoEnvelopeProps",
@@ -29,12 +30,12 @@ export const DocumensoEnvelopeStateSchema = Schema.Literals([
29
30
  ]);
30
31
  export const DocumensoEnvelopeDocumentSchema = Schema.Struct({
31
32
  fileName: Schema.NonEmptyString,
32
- mimeType: Schema.NonEmptyString,
33
+ mimeType: Schema.Literal("application/pdf"),
33
34
  content: Schema.Uint8Array,
34
35
  });
35
36
  export const DocumensoEnvelopeDocumentPropsSchema = Schema.Struct({
36
37
  fileName: Schema.NonEmptyString,
37
- mimeType: Schema.NonEmptyString,
38
+ mimeType: Schema.Literal("application/pdf"),
38
39
  contentBase64: base64String,
39
40
  });
40
41
  export const DocumensoRecipientRoleSchema = Schema.Literals(["approver", "signer"]);
@@ -42,7 +43,7 @@ export const DocumensoEnvelopeRecipientSchema = Schema.Struct({
42
43
  name: Schema.NonEmptyString,
43
44
  email: Schema.NonEmptyString,
44
45
  role: Schema.optional(DocumensoRecipientRoleSchema),
45
- routingOrder: Schema.optional(Schema.Number),
46
+ routingOrder: Schema.optional(Schema.Finite),
46
47
  });
47
48
  export const DocumensoEnvelopeInputSchema = Schema.Struct({
48
49
  title: Schema.NonEmptyString,
@@ -75,22 +76,25 @@ export const DocumensoEnvelopeSchema = Schema.Struct({
75
76
  });
76
77
  const documensoSignatureRequestNoopDiff = { action: "noop" };
77
78
  const documensoSignatureRequestDiff = ({ olds, }) => Effect.succeed(olds === undefined ? undefined : documensoSignatureRequestNoopDiff);
78
- const documensoSignatureRequestInputFromProps = (props) => {
79
+ const documensoSignatureRequestInputFromProps = Effect.fn(function* (props) {
79
80
  const [firstDocument, ...restDocuments] = props.documents;
81
+ const firstContent = yield* base64ToBytes(firstDocument.contentBase64).pipe(Effect.orDie);
82
+ const decodedRestDocuments = yield* Effect.forEach(restDocuments, (document) => base64ToBytes(document.contentBase64).pipe(Effect.orDie, Effect.map((content) => ({
83
+ fileName: document.fileName,
84
+ mimeType: document.mimeType,
85
+ content,
86
+ }))));
87
+ const documents = [
88
+ {
89
+ fileName: firstDocument.fileName,
90
+ mimeType: firstDocument.mimeType,
91
+ content: firstContent,
92
+ },
93
+ ...decodedRestDocuments,
94
+ ];
80
95
  return {
81
96
  title: props.title,
82
- documents: [
83
- {
84
- fileName: firstDocument.fileName,
85
- mimeType: firstDocument.mimeType,
86
- content: Uint8Array.fromBase64(firstDocument.contentBase64),
87
- },
88
- ...restDocuments.map((document) => ({
89
- fileName: document.fileName,
90
- mimeType: document.mimeType,
91
- content: Uint8Array.fromBase64(document.contentBase64),
92
- })),
93
- ],
97
+ documents,
94
98
  recipients: props.recipients,
95
99
  ...(props.subject === undefined ? {} : { subject: props.subject }),
96
100
  ...(props.message === undefined ? {} : { message: props.message }),
@@ -98,7 +102,7 @@ const documensoSignatureRequestInputFromProps = (props) => {
98
102
  ...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
99
103
  ...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
100
104
  };
101
- };
105
+ });
102
106
  const documensoSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(DocumensoEnvelopePropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
103
107
  code: SignatureKitErrorCodeValue.invalidInput,
104
108
  retryable: false,
@@ -106,7 +110,7 @@ const documensoSignatureRequestInputFromResourceProps = (props) => Schema.decode
106
110
  operation: SignatureKitOperationValue.schemaDecode,
107
111
  schemaName: DocumensoSchemaName.signatureRequestProps,
108
112
  issueMessage: String(issue),
109
- })), Effect.map(documensoSignatureRequestInputFromProps));
113
+ })), Effect.flatMap(documensoSignatureRequestInputFromProps));
110
114
  const DOCUMENSO_PROVIDER_COLLECTION_ID = "@signature-kit/documenso/Providers";
111
115
  const DEFAULT_BASE_URL = "https://app.documenso.com/api/v2";
112
116
  const DOCUMENSO_LIST_FIRST_PAGE = 1;
@@ -122,11 +126,11 @@ const DocumensoCreateEnvelopeResultSchema = Schema.Struct({
122
126
  id: Schema.NonEmptyString,
123
127
  });
124
128
  const DocumensoRecipientResultSchema = Schema.Struct({
125
- id: Schema.Number,
129
+ id: Schema.Finite,
126
130
  name: Schema.String,
127
131
  email: Schema.String,
128
132
  role: Schema.String,
129
- signingOrder: Schema.optional(Schema.NullOr(Schema.Number)),
133
+ signingOrder: Schema.optional(Schema.NullOr(Schema.Finite)),
130
134
  signingUrl: Schema.optional(Schema.String),
131
135
  });
132
136
  const DocumensoDistributeEnvelopeResultSchema = Schema.Struct({
@@ -135,7 +139,7 @@ const DocumensoDistributeEnvelopeResultSchema = Schema.Struct({
135
139
  recipients: Schema.Array(DocumensoRecipientResultSchema),
136
140
  });
137
141
  const DocumensoEnvelopeRecipientResultSchema = Schema.Struct({
138
- id: Schema.Union([Schema.NonEmptyString, Schema.Number]),
142
+ id: Schema.Union([Schema.NonEmptyString, Schema.Finite]),
139
143
  name: Schema.String,
140
144
  email: Schema.String,
141
145
  role: Schema.String,
@@ -151,26 +155,26 @@ const DocumensoEnvelopeResultSchema = Schema.Struct({
151
155
  envelopeItems: Schema.optional(Schema.Array(DocumensoEnvelopeItemResultSchema)),
152
156
  });
153
157
  const DocumensoEnvelopeListPaginationSchema = Schema.Struct({
154
- page: Schema.Number,
155
- perPage: Schema.Number,
156
- totalPages: Schema.Number,
157
- totalItems: Schema.Number,
158
+ page: Schema.Finite,
159
+ perPage: Schema.Finite,
160
+ totalPages: Schema.Finite,
161
+ totalItems: Schema.Finite,
158
162
  });
159
163
  const DocumensoEnvelopeListResultSchema = Schema.Struct({
160
164
  data: Schema.Array(DocumensoEnvelopeResultSchema),
161
165
  pagination: DocumensoEnvelopeListPaginationSchema,
162
166
  });
163
167
  export const DocumensoSignatureRequest = Resource("SignatureKit.DocumensoSignatureRequest", { defaultRemovalPolicy: "retain" });
164
- export class DocumensoCredentials extends Context.Service()("@signature-kit/documenso/Credentials") {
168
+ class DocumensoCredentials extends Context.Service()("@signature-kit/documenso/Credentials") {
165
169
  }
166
- export const documensoCredentialsLayer = (options) => Layer.effect(DocumensoCredentials, Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
170
+ const documensoCredentialsLayer = (options) => Layer.effect(DocumensoCredentials, Effect.cached(Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
167
171
  code: SignatureKitErrorCodeValue.invalidInput,
168
172
  retryable: false,
169
173
  provider: PROVIDER,
170
174
  operation: SignatureKitOperationValue.schemaDecode,
171
175
  schemaName: DocumensoSchemaName.providerOptions,
172
176
  issueMessage: String(issue),
173
- }))));
177
+ })))));
174
178
  const documensoBaseUrl = (options) => options.baseUrl === undefined ? DEFAULT_BASE_URL : normalizedBaseUrl(options.baseUrl);
175
179
  const documensoAuthorization = (options) => {
176
180
  const token = Redacted.value(options.apiKey);
@@ -241,8 +245,6 @@ const distributeEnvelope = (http, options, baseUrl, input, envelope) => http
241
245
  .pipe(Effect.map((result) => ({
242
246
  provider: PROVIDER,
243
247
  id: result.id,
244
- // A failed distribution means recipients were never notified — surface
245
- // the envelope as still-draft rather than pretending it was sent.
246
248
  state: result.success ? "sent" : "draft",
247
249
  providerStatus: result.success ? "distributed" : "not_distributed",
248
250
  detailsUrl: `${baseUrl}/envelope/${documensoPathId(result.id)}`,
@@ -304,24 +306,22 @@ const fetchEnvelopeResult = (http, options, baseUrl, id) => http.requestJson({
304
306
  headers: { Authorization: documensoAuthorization(options) },
305
307
  }, DocumensoEnvelopeResultSchema, DocumensoSchemaName.envelopeResult);
306
308
  const getEnvelope = (http, options, baseUrl, id) => fetchEnvelopeResult(http, options, baseUrl, id).pipe(Effect.map((result) => mapEnvelopeToDocumensoEnvelope(baseUrl, result)));
307
- const listEnvelopes = (http, options, baseUrl) => {
308
- return Stream.paginate(DOCUMENSO_LIST_FIRST_PAGE, (page) => {
309
- const url = new URL(`${baseUrl}/envelope`);
310
- url.searchParams.set("page", String(page));
311
- url.searchParams.set("perPage", String(DOCUMENSO_LIST_PER_PAGE));
312
- return http
313
- .requestJson({
314
- provider: PROVIDER,
315
- method: "GET",
316
- url: url.toString(),
317
- headers: { Authorization: documensoAuthorization(options) },
318
- }, DocumensoEnvelopeListResultSchema, DocumensoSchemaName.envelopeListResult)
319
- .pipe(Effect.map((result) => [
320
- result.data.map((envelope) => mapEnvelopeToDocumensoEnvelope(baseUrl, envelope)),
321
- documensoNextPage(result.pagination, page),
322
- ]));
323
- }).pipe(Stream.runCollect);
324
- };
309
+ const listEnvelopes = (http, options, baseUrl) => Stream.paginate(DOCUMENSO_LIST_FIRST_PAGE, (page) => {
310
+ const url = new URL(`${baseUrl}/envelope`);
311
+ url.searchParams.set("page", String(page));
312
+ url.searchParams.set("perPage", String(DOCUMENSO_LIST_PER_PAGE));
313
+ return http
314
+ .requestJson({
315
+ provider: PROVIDER,
316
+ method: "GET",
317
+ url: url.toString(),
318
+ headers: { Authorization: documensoAuthorization(options) },
319
+ }, DocumensoEnvelopeListResultSchema, DocumensoSchemaName.envelopeListResult)
320
+ .pipe(Effect.map((result) => [
321
+ result.data.map((envelope) => mapEnvelopeToDocumensoEnvelope(baseUrl, envelope)),
322
+ documensoNextPage(result.pagination, page),
323
+ ]));
324
+ }).pipe(Stream.runCollect);
325
325
  const cancelEnvelope = (http, options, baseUrl, envelopeId) => http.requestVoid({
326
326
  provider: PROVIDER,
327
327
  method: "POST",
@@ -383,35 +383,40 @@ const createDocumensoEnvelopeRequest = (http, options, baseUrl, input) => create
383
383
  detailsUrl: `${baseUrl}/envelope/${documensoPathId(envelope.id)}`,
384
384
  });
385
385
  }
386
- return distributeEnvelope(http, options, baseUrl, input, envelope).pipe(Effect.catch((error) => shouldRollbackDocumensoCreate(error)
387
- ? deleteEnvelope(http, options, baseUrl, envelope.id).pipe(Effect.catch(() => Effect.void), Effect.flatMap(() => Effect.fail(error)))
388
- : Effect.fail(error)));
386
+ return distributeEnvelope(http, options, baseUrl, input, envelope).pipe(Effect.catchIf(shouldRollbackDocumensoCreate, (error) => deleteEnvelope(http, options, baseUrl, envelope.id).pipe(Effect.ignore, Effect.flatMap(() => Effect.fail(error)))));
389
387
  }));
390
- export const DocumensoSignatureRequestProvider = () => Provider.effect(DocumensoSignatureRequest, Effect.gen(function* () {
391
- const options = yield* DocumensoCredentials;
388
+ const documensoSignatureRequestProvider = Provider.effect(DocumensoSignatureRequest, Effect.gen(function* () {
389
+ const credentials = yield* DocumensoCredentials;
392
390
  const http = yield* SignatureHttpClient;
393
- const baseUrl = documensoBaseUrl(options);
394
391
  return DocumensoSignatureRequest.Provider.of({
395
392
  nuke: { skip: true },
396
393
  diff: documensoSignatureRequestDiff,
397
- list: () =>
398
- // Retained resources must not feed account-wide nuke enumeration.
399
- Effect.succeed([]),
400
- read: ({ output }) => output === undefined
401
- ? Effect.succeed(undefined)
402
- : getEnvelope(http, options, baseUrl, output.id).pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined))),
394
+ list: () => Effect.succeed([]),
395
+ read: Effect.fn(function* ({ output }) {
396
+ if (output === undefined)
397
+ return undefined;
398
+ const options = yield* credentials;
399
+ const baseUrl = documensoBaseUrl(options);
400
+ return yield* getEnvelope(http, options, baseUrl, output.id).pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined)));
401
+ }),
403
402
  reconcile: Effect.fn(function* ({ news, output }) {
404
403
  if (output !== undefined)
405
404
  return output;
405
+ const options = yield* credentials;
406
+ const baseUrl = documensoBaseUrl(options);
406
407
  const input = yield* documensoSignatureRequestInputFromResourceProps(news);
407
408
  return yield* createDocumensoEnvelopeRequest(http, options, baseUrl, input);
408
409
  }),
409
- delete: ({ output }) => deleteEnvelope(http, options, baseUrl, output.id),
410
+ delete: Effect.fn(function* ({ output }) {
411
+ const options = yield* credentials;
412
+ const baseUrl = documensoBaseUrl(options);
413
+ return yield* deleteEnvelope(http, options, baseUrl, output.id);
414
+ }),
410
415
  });
411
416
  }));
412
- export class DocumensoProviders extends Provider.ProviderCollection()(DOCUMENSO_PROVIDER_COLLECTION_ID) {
417
+ class DocumensoProviders extends Provider.ProviderCollection()(DOCUMENSO_PROVIDER_COLLECTION_ID) {
413
418
  }
414
- export const providers = (options) => Layer.effect(DocumensoProviders, Provider.collection([DocumensoSignatureRequest])).pipe(Layer.provide(DocumensoSignatureRequestProvider()), Layer.provide(documensoCredentialsLayer(options)));
419
+ export const providers = (options) => Layer.effect(DocumensoProviders, Provider.collection([DocumensoSignatureRequest])).pipe(Layer.provide(Layer.fresh(documensoSignatureRequestProvider)), Layer.provide(documensoCredentialsLayer(options)));
415
420
  export const getDocumensoSignatureRequest = (options, id) => Effect.gen(function* () {
416
421
  const valid = yield* Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
417
422
  code: SignatureKitErrorCodeValue.invalidInput,
@@ -472,3 +477,18 @@ export const downloadDocumensoSignedDocument = (options, envelopeId) => Effect.g
472
477
  const http = yield* SignatureHttpClient;
473
478
  return yield* downloadSignedEnvelopeDocument(http, valid, documensoBaseUrl(valid), envelopeId);
474
479
  });
480
+ export const waitForDocumensoSignatureRequest = Effect.fn(function* (options, id, pollInterval) {
481
+ const interval = yield* Schema.decodeUnknownEffect(Schema.Duration.check(Schema.makeFilter((value) => Duration.isFinite(value) && Duration.isPositive(value))))(pollInterval).pipe(Effect.mapError((issue) => new SignatureKitError({
482
+ code: SignatureKitErrorCodeValue.invalidInput,
483
+ retryable: false,
484
+ provider: PROVIDER,
485
+ operation: SignatureKitOperationValue.schemaDecode,
486
+ schemaName: "DocumensoPollInterval",
487
+ issueMessage: String(issue),
488
+ reason: "Polling requires a positive, finite interval.",
489
+ })));
490
+ return yield* getDocumensoSignatureRequest(options, id).pipe(Effect.repeat({
491
+ while: (request) => Match.value(request.state).pipe(Match.whenOr("draft", "sent", () => true), Match.whenOr("completed", "cancelled", "deleted", "declined", "expired", () => false), Match.exhaustive),
492
+ schedule: Schedule.spaced(interval),
493
+ }));
494
+ });
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@signature-kit/documenso",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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": {
32
+ "@signature-kit/crypto": "^0.2.1",
30
33
  "@signature-kit/http": "^0.1.0",
31
- "@signature-kit/signatures": "^0.1.0",
32
- "alchemy": "2.0.0-beta.57",
33
- "effect": "4.0.0-beta.86"
34
+ "@signature-kit/signatures": "^0.3.0",
35
+ "alchemy": "2.0.0-beta.85",
36
+ "effect": "4.1.0"
34
37
  },
35
38
  "nx": {
36
39
  "targets": {
37
40
  "npm-pack": {
38
41
  "executor": "nx:run-commands",
39
42
  "options": {
40
- "command": "npm pack --dry-run --json",
43
+ "command": "bun pm pack --dry-run",
41
44
  "cwd": "{projectRoot}"
42
45
  }
43
46
  },