@signature-kit/docuseal 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 CHANGED
@@ -1,9 +1,31 @@
1
+ ## @signature-kit/docuseal@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 `DocuSealSignatureRequest` through `providers(options)`.
22
+
3
23
  ## 0.3.0
4
24
 
5
25
  - DocuSeal now owns its submission props, attributes, state schema, schema names,
6
26
  and retained no-op diff instead of using core remote-signature contracts.
27
+ - Decode provider options through a cached credential Effect, so retained-resource
28
+ `list` hooks and `read` calls without cached output do not touch credentials.
7
29
  - Refuse signed-document downloads before a submission is completed, returning a
8
30
  typed `unsupportedOperation` instead of silently returning the unsigned source
9
31
  document.
package/README.md CHANGED
@@ -8,11 +8,15 @@ Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, l
8
8
  bun add @signature-kit/docuseal @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 DocuSeal credentials and resource providers.
11
+ `effect` and `alchemy` are direct runtime dependencies. Provide
12
+ `signatureHttpClientLive` at the stack boundary; `providers(options)` supplies
13
+ only DocuSeal 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/docuseal` — DocuSeal submission/document/submitter schemas, `DocuSealSignatureRequest`, `DocuSealProviders`, `providers`, `getDocuSealSignatureRequest`, `listDocuSealSignatureRequests`, `deleteDocuSealSignatureRequest`, and `downloadDocuSealSignedDocument`.
19
+ - `@signature-kit/docuseal` — DocuSeal submission/document/submitter schemas, `DocuSealSignatureRequest`, `providers`, `getDocuSealSignatureRequest`, `listDocuSealSignatureRequests`, `deleteDocuSealSignatureRequest`, and `downloadDocuSealSignedDocument`.
16
20
 
17
21
  Capability matrix:
18
22
 
@@ -69,6 +73,25 @@ export const downloadSigned = (id: string) =>
69
73
  downloadDocuSealSignedDocument(options, id).pipe(Effect.provide(signatureHttpClientLive));
70
74
  ```
71
75
 
76
+ ## Wait for a final state
77
+
78
+ `waitForDocuSealSignatureRequest(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:
79
+
80
+ ```ts
81
+ import { waitForDocuSealSignatureRequest } from "@signature-kit/docuseal";
82
+ import { signatureHttpClientLive } from "@signature-kit/http";
83
+ import { Duration, Effect } from "effect";
84
+ import type { DocuSealProviderOptions } from "@signature-kit/docuseal";
85
+
86
+ declare const options: DocuSealProviderOptions;
87
+ declare const requestId: string;
88
+
89
+ const program = waitForDocuSealSignatureRequest(options, requestId, Duration.seconds(2)).pipe(
90
+ Effect.timeout(Duration.minutes(5)),
91
+ Effect.provide(signatureHttpClientLive),
92
+ );
93
+ ```
94
+
72
95
  ## Errors and i18n
73
96
 
74
97
  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 DocuSealProviderId = "docuseal";
7
7
  export declare const DocuSealSubmissionStateSchema: Schema.Literals<readonly ["draft", "sent", "completed", "cancelled", "deleted", "declined", "expired"]>;
8
8
  export type DocuSealSubmissionState = (typeof DocuSealSubmissionStateSchema)["Type"];
9
9
  export declare const DocuSealSubmissionDocumentSchema: 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 DocuSealSubmissionDocument = (typeof DocuSealSubmissionDocumentSchema)["Type"];
15
15
  export declare const DocuSealSubmissionDocumentPropsSchema: 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 DocuSealSubmissionDocumentProps = (typeof DocuSealSubmissionDocumentPropsSchema)["Type"];
@@ -22,7 +22,7 @@ export declare const DocuSealSubmitterSchema: Schema.Struct<{
22
22
  readonly name: Schema.NonEmptyString;
23
23
  readonly email: Schema.NonEmptyString;
24
24
  readonly role: Schema.optional<Schema.NonEmptyString>;
25
- readonly routingOrder: Schema.optional<Schema.Number>;
25
+ readonly routingOrder: Schema.optional<Schema.Finite>;
26
26
  }>;
27
27
  export type DocuSealSubmitter = (typeof DocuSealSubmitterSchema)["Type"];
28
28
  export declare const DocuSealSubmissionInputSchema: Schema.Struct<{
@@ -31,14 +31,14 @@ export declare const DocuSealSubmissionInputSchema: Schema.Struct<{
31
31
  readonly message: Schema.optional<Schema.NonEmptyString>;
32
32
  readonly documents: Schema.NonEmptyArray<Schema.Struct<{
33
33
  readonly fileName: Schema.NonEmptyString;
34
- readonly mimeType: Schema.NonEmptyString;
34
+ readonly mimeType: Schema.Literal<"application/pdf">;
35
35
  readonly content: Schema.Uint8Array;
36
36
  }>>;
37
37
  readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
38
38
  readonly name: Schema.NonEmptyString;
39
39
  readonly email: Schema.NonEmptyString;
40
40
  readonly role: Schema.optional<Schema.NonEmptyString>;
41
- readonly routingOrder: Schema.optional<Schema.Number>;
41
+ readonly routingOrder: Schema.optional<Schema.Finite>;
42
42
  }>>;
43
43
  readonly send: Schema.optional<Schema.Boolean>;
44
44
  readonly expiresAt: Schema.optional<Schema.Date>;
@@ -51,14 +51,14 @@ export declare const DocuSealSubmissionPropsSchema: Schema.Struct<{
51
51
  readonly message: Schema.optional<Schema.NonEmptyString>;
52
52
  readonly documents: Schema.NonEmptyArray<Schema.Struct<{
53
53
  readonly fileName: Schema.NonEmptyString;
54
- readonly mimeType: Schema.NonEmptyString;
54
+ readonly mimeType: Schema.Literal<"application/pdf">;
55
55
  readonly contentBase64: Schema.ConstraintDecoder<string, never>;
56
56
  }>>;
57
57
  readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
58
58
  readonly name: Schema.NonEmptyString;
59
59
  readonly email: Schema.NonEmptyString;
60
60
  readonly role: Schema.optional<Schema.NonEmptyString>;
61
- readonly routingOrder: Schema.optional<Schema.Number>;
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>;
@@ -86,23 +86,27 @@ export declare const DocuSealProviderOptionsSchema: Schema.Struct<{
86
86
  export type DocuSealProviderOptions = (typeof DocuSealProviderOptionsSchema)["Type"];
87
87
  export type DocuSealSignatureRequest = Resource<"SignatureKit.DocuSealSignatureRequest", DocuSealSubmissionProps, DocuSealSubmissionAttributes>;
88
88
  export declare const DocuSealSignatureRequest: import("alchemy").ResourceClass<DocuSealSignatureRequest>;
89
- declare const DocuSealCredentials_base: Context.ServiceClass<DocuSealCredentials, "@signature-kit/docuseal/Credentials", {
90
- readonly apiKey: Redacted.Redacted<string>;
91
- readonly baseUrl?: string | undefined;
92
- readonly sendSms?: boolean | undefined;
93
- readonly submittersOrder?: "preserved" | "random" | undefined;
94
- }>;
95
- export declare class DocuSealCredentials extends DocuSealCredentials_base {
96
- }
97
- export declare const docuSealCredentialsLayer: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealCredentials, SignatureKitError>;
98
- export declare const DocuSealSignatureRequestProvider: () => Layer.Layer<Provider.Provider<DocuSealSignatureRequest>, never, DocuSealCredentials | SignatureHttpClient>;
99
89
  declare const DocuSealProviders_base: Provider.ProviderCollection<DocuSealProviders, "@signature-kit/docuseal/Providers">;
100
- export declare class DocuSealProviders extends DocuSealProviders_base {
90
+ declare class DocuSealProviders extends DocuSealProviders_base {
101
91
  }
102
- export declare const providers: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealProviders, SignatureKitError, SignatureHttpClient>;
92
+ export declare const providers: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealProviders, never, SignatureHttpClient>;
103
93
  export declare const getDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<DocuSealSubmissionAttributes, SignatureKitError, SignatureHttpClient>;
104
94
  export declare const listDocuSealSignatureRequests: (options: DocuSealProviderOptions) => Effect.Effect<readonly DocuSealSubmissionAttributes[], SignatureKitError, SignatureHttpClient>;
105
95
  export declare const deleteDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
106
96
  export declare const downloadDocuSealSignedDocument: (options: DocuSealProviderOptions, id: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
97
+ export declare const waitForDocuSealSignatureRequest: (options: {
98
+ readonly apiKey: Redacted.Redacted<string>;
99
+ readonly baseUrl?: string | undefined;
100
+ readonly sendSms?: boolean | undefined;
101
+ readonly submittersOrder?: "preserved" | "random" | undefined;
102
+ }, id: string, pollInterval: Duration.Duration) => Effect.Effect<{
103
+ readonly provider: "docuseal";
104
+ readonly id: string;
105
+ readonly state: "cancelled" | "completed" | "declined" | "deleted" | "draft" | "expired" | "sent";
106
+ readonly providerStatus?: string | undefined;
107
+ readonly signingUrl?: string | undefined;
108
+ readonly detailsUrl?: string | undefined;
109
+ readonly downloadUrl?: string | undefined;
110
+ }, SignatureKitError, SignatureHttpClient>;
107
111
  export {};
108
112
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,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,QA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mE/F,QAAA,MAAM,6BAA6B,mDAA2C,CAAC;AAC/E,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAErF,eAAO,MAAM,6BAA6B;;;;;EAKxC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AA6DrF,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAC7C,uCAAuC,EACvC,uBAAuB,EACvB,4BAA4B,CAC7B,CAAC;AAEF,eAAO,MAAM,wBAAwB,2DAGpC,CAAC;;AAwYF,cAAM,iBAAkB,SAAQ,sBAE/B;CAAG;AAEJ,eAAO,MAAM,SAAS,YAAa,uBAAuB,+DAIvD,CAAC;AAEJ,eAAO,MAAM,2BAA2B,YAC7B,uBAAuB,MAC5B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,4BAA4B,EAAE,iBAAiB,EAAE,mBAAmB,CAoBjF,CAAC;AAEL,eAAO,MAAM,6BAA6B,YAC/B,uBAAuB,KAC/B,MAAM,CAAC,MAAM,CAAC,SAAS,4BAA4B,EAAE,EAAE,iBAAiB,EAAE,mBAAmB,CAiB5F,CAAC;AAEL,eAAO,MAAM,8BAA8B,YAChC,uBAAuB,MAC5B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,8BAA8B,YAChC,uBAAuB,MAC5B,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAiB/D,CAAC;AAEL,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;0CAkC1C,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 DocuSealSchemaName = {
8
8
  providerOptions: "DocuSealProviderOptions",
9
9
  signatureRequestProps: "DocuSealSubmissionProps",
@@ -29,19 +29,19 @@ export const DocuSealSubmissionStateSchema = Schema.Literals([
29
29
  ]);
30
30
  export const DocuSealSubmissionDocumentSchema = Schema.Struct({
31
31
  fileName: Schema.NonEmptyString,
32
- mimeType: Schema.NonEmptyString,
32
+ mimeType: Schema.Literal("application/pdf"),
33
33
  content: Schema.Uint8Array,
34
34
  });
35
35
  export const DocuSealSubmissionDocumentPropsSchema = Schema.Struct({
36
36
  fileName: Schema.NonEmptyString,
37
- mimeType: Schema.NonEmptyString,
37
+ mimeType: Schema.Literal("application/pdf"),
38
38
  contentBase64: base64String,
39
39
  });
40
40
  export const DocuSealSubmitterSchema = Schema.Struct({
41
41
  name: Schema.NonEmptyString,
42
42
  email: Schema.NonEmptyString,
43
43
  role: Schema.optional(Schema.NonEmptyString),
44
- routingOrder: Schema.optional(Schema.Number),
44
+ routingOrder: Schema.optional(Schema.Finite),
45
45
  });
46
46
  export const DocuSealSubmissionInputSchema = Schema.Struct({
47
47
  title: Schema.NonEmptyString,
@@ -74,22 +74,25 @@ export const DocuSealSubmissionAttributesSchema = Schema.Struct({
74
74
  });
75
75
  const docusealSignatureRequestNoopDiff = { action: "noop" };
76
76
  const docusealSignatureRequestDiff = ({ olds, }) => Effect.succeed(olds === undefined ? undefined : docusealSignatureRequestNoopDiff);
77
- const docusealSignatureRequestInputFromProps = (props) => {
77
+ const docusealSignatureRequestInputFromProps = Effect.fn(function* (props) {
78
78
  const [firstDocument, ...restDocuments] = props.documents;
79
+ const firstContent = yield* base64ToBytes(firstDocument.contentBase64).pipe(Effect.orDie);
80
+ const decodedRestDocuments = yield* Effect.forEach(restDocuments, (document) => base64ToBytes(document.contentBase64).pipe(Effect.orDie, Effect.map((content) => ({
81
+ fileName: document.fileName,
82
+ mimeType: document.mimeType,
83
+ content,
84
+ }))));
85
+ const documents = [
86
+ {
87
+ fileName: firstDocument.fileName,
88
+ mimeType: firstDocument.mimeType,
89
+ content: firstContent,
90
+ },
91
+ ...decodedRestDocuments,
92
+ ];
79
93
  return {
80
94
  title: props.title,
81
- documents: [
82
- {
83
- fileName: firstDocument.fileName,
84
- mimeType: firstDocument.mimeType,
85
- content: Uint8Array.fromBase64(firstDocument.contentBase64),
86
- },
87
- ...restDocuments.map((document) => ({
88
- fileName: document.fileName,
89
- mimeType: document.mimeType,
90
- content: Uint8Array.fromBase64(document.contentBase64),
91
- })),
92
- ],
95
+ documents,
93
96
  recipients: props.recipients,
94
97
  ...(props.subject === undefined ? {} : { subject: props.subject }),
95
98
  ...(props.message === undefined ? {} : { message: props.message }),
@@ -97,7 +100,7 @@ const docusealSignatureRequestInputFromProps = (props) => {
97
100
  ...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
98
101
  ...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
99
102
  };
100
- };
103
+ });
101
104
  const docusealSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(DocuSealSubmissionPropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
102
105
  code: SignatureKitErrorCodeValue.invalidInput,
103
106
  retryable: false,
@@ -105,7 +108,7 @@ const docusealSignatureRequestInputFromResourceProps = (props) => Schema.decodeU
105
108
  operation: SignatureKitOperationValue.schemaDecode,
106
109
  schemaName: DocuSealSchemaName.signatureRequestProps,
107
110
  issueMessage: String(issue),
108
- })), Effect.map(docusealSignatureRequestInputFromProps));
111
+ })), Effect.flatMap(docusealSignatureRequestInputFromProps));
109
112
  const DOCUSEAL_PROVIDER_COLLECTION_ID = "@signature-kit/docuseal/Providers";
110
113
  const DEFAULT_BASE_URL = "https://api.docuseal.com";
111
114
  const DocuSealSubmittersOrderSchema = Schema.Literals(["preserved", "random"]);
@@ -115,7 +118,7 @@ export const DocuSealProviderOptionsSchema = Schema.Struct({
115
118
  sendSms: Schema.optional(Schema.Boolean),
116
119
  submittersOrder: Schema.optional(DocuSealSubmittersOrderSchema),
117
120
  });
118
- const DocuSealSubmissionIdSchema = Schema.Union([Schema.Number, Schema.NonEmptyString]);
121
+ const DocuSealSubmissionIdSchema = Schema.Union([Schema.Finite, Schema.NonEmptyString]);
119
122
  const DocuSealSubmitterLinkFields = {
120
123
  embed_src: Schema.optional(Schema.NullOr(Schema.String)),
121
124
  signing_url: Schema.optional(Schema.NullOr(Schema.String)),
@@ -155,25 +158,25 @@ const DocuSealSubmissionDocumentsResultSchema = Schema.Struct({
155
158
  })),
156
159
  });
157
160
  const DocuSealPaginationSchema = Schema.Struct({
158
- count: Schema.Number,
159
- next: Schema.NullOr(Schema.Number),
160
- prev: Schema.NullOr(Schema.Number),
161
+ count: Schema.Finite,
162
+ next: Schema.NullOr(Schema.Finite),
163
+ prev: Schema.NullOr(Schema.Finite),
161
164
  });
162
165
  const DocuSealSubmissionsResultSchema = Schema.Struct({
163
166
  data: Schema.Array(DocuSealSubmissionResultSchema),
164
167
  pagination: DocuSealPaginationSchema,
165
168
  });
166
169
  export const DocuSealSignatureRequest = Resource("SignatureKit.DocuSealSignatureRequest", { defaultRemovalPolicy: "retain" });
167
- export class DocuSealCredentials extends Context.Service()("@signature-kit/docuseal/Credentials") {
170
+ class DocuSealCredentials extends Context.Service()("@signature-kit/docuseal/Credentials") {
168
171
  }
169
- export const docuSealCredentialsLayer = (options) => Layer.effect(DocuSealCredentials, Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
172
+ const docuSealCredentialsLayer = (options) => Layer.effect(DocuSealCredentials, Effect.cached(Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
170
173
  code: SignatureKitErrorCodeValue.invalidInput,
171
174
  retryable: false,
172
175
  provider: PROVIDER,
173
176
  operation: SignatureKitOperationValue.schemaDecode,
174
177
  schemaName: DocuSealSchemaName.providerOptions,
175
178
  issueMessage: String(issue),
176
- }))));
179
+ })))));
177
180
  const docuSealBaseUrl = (options) => options.baseUrl === undefined ? DEFAULT_BASE_URL : normalizedBaseUrl(options.baseUrl);
178
181
  const authHeaders = (options) => ({
179
182
  "X-Auth-Token": Redacted.value(options.apiKey),
@@ -187,9 +190,6 @@ const docuSealSubmissionListUrl = (baseUrl, after) => {
187
190
  url.searchParams.set("after", after.toString());
188
191
  return url.toString();
189
192
  };
190
- const docuSealSubmissionsNextUrl = (baseUrl, pagination) => pagination.next === null
191
- ? Option.none()
192
- : Option.some(docuSealSubmissionListUrl(baseUrl, pagination.next));
193
193
  const DocuSealStatusSchema = Schema.Literals([
194
194
  "draft",
195
195
  "completed",
@@ -229,8 +229,6 @@ const toDocuSealSubmissionAttributes = (baseUrl, submission) => {
229
229
  const id = normalizeSubmissionId(submission.id);
230
230
  const signingUrl = pickSigningUrl(submission);
231
231
  const state = docuSealSubmissionState(submission.status);
232
- // Before completion, documents[0].url points at the UNSIGNED source file —
233
- // advertising it as downloadUrl would hand callers unsigned bytes.
234
232
  const downloadUrl = state === "completed" ? pickDownloadUrl(submission) : undefined;
235
233
  return {
236
234
  provider: PROVIDER,
@@ -267,7 +265,6 @@ const createSubmission = (http, options, baseUrl, input) => {
267
265
  file: bytesToBase64(document.content),
268
266
  position: index,
269
267
  })),
270
- // DocuSeal accepts completed_redirect_url as both a submission default and a submitter override.
271
268
  submitters: input.recipients.map((recipient, index) => ({
272
269
  name: recipient.name,
273
270
  email: recipient.email,
@@ -307,17 +304,38 @@ const createSubmission = (http, options, baseUrl, input) => {
307
304
  };
308
305
  }));
309
306
  };
310
- const listSubmissions = (http, options, baseUrl) => Stream.paginate(docuSealSubmissionListUrl(baseUrl), (url) => http
311
- .requestJson({
312
- provider: PROVIDER,
313
- method: "GET",
314
- url,
315
- headers: authHeaders(options),
316
- }, DocuSealSubmissionsResultSchema, DocuSealSchemaName.submissionsResult)
317
- .pipe(Effect.map((result) => [
318
- result.data.map((submission) => toDocuSealSubmissionAttributes(baseUrl, submission)),
319
- docuSealSubmissionsNextUrl(baseUrl, result.pagination),
320
- ]))).pipe(Stream.runCollect);
307
+ const listSubmissions = (http, options, baseUrl) => Stream.paginate({ after: Option.none(), visited: new Set() }, (state) => {
308
+ if (Option.isSome(state.after) && state.visited.has(state.after.value)) {
309
+ return Effect.fail(new SignatureKitError({
310
+ code: SignatureKitErrorCodeValue.responseShape,
311
+ retryable: false,
312
+ provider: PROVIDER,
313
+ operation: SignatureKitOperationValue.httpDecode,
314
+ schemaName: DocuSealSchemaName.submissionsResult,
315
+ reason: "DocuSeal list pagination returned a repeated cursor.",
316
+ }));
317
+ }
318
+ const nextVisited = new Set(state.visited);
319
+ if (Option.isSome(state.after))
320
+ nextVisited.add(state.after.value);
321
+ const url = docuSealSubmissionListUrl(baseUrl, Option.isSome(state.after) ? state.after.value : undefined);
322
+ return http
323
+ .requestJson({
324
+ provider: PROVIDER,
325
+ method: "GET",
326
+ url,
327
+ headers: authHeaders(options),
328
+ }, DocuSealSubmissionsResultSchema, DocuSealSchemaName.submissionsResult)
329
+ .pipe(Effect.map((result) => [
330
+ result.data.map((submission) => toDocuSealSubmissionAttributes(baseUrl, submission)),
331
+ result.pagination.next === null
332
+ ? Option.none()
333
+ : Option.some({
334
+ after: Option.some(result.pagination.next),
335
+ visited: nextVisited,
336
+ }),
337
+ ]));
338
+ }).pipe(Stream.runCollect);
321
339
  const fetchSubmission = (http, options, baseUrl, id) => http.requestJson({
322
340
  provider: PROVIDER,
323
341
  method: "GET",
@@ -365,31 +383,38 @@ const downloadDocumentFromSubmission = (http, options, baseUrl, id) => fetchSubm
365
383
  return requestBytesFromUrl(http, url);
366
384
  }));
367
385
  }));
368
- export const DocuSealSignatureRequestProvider = () => Provider.effect(DocuSealSignatureRequest, Effect.gen(function* () {
369
- const options = yield* DocuSealCredentials;
386
+ const docuSealSignatureRequestProvider = Provider.effect(DocuSealSignatureRequest, Effect.gen(function* () {
387
+ const credentials = yield* DocuSealCredentials;
370
388
  const http = yield* SignatureHttpClient;
371
- const baseUrl = docuSealBaseUrl(options);
372
389
  return DocuSealSignatureRequest.Provider.of({
373
390
  nuke: { skip: true },
374
391
  diff: docusealSignatureRequestDiff,
375
- list: () =>
376
- // Retained resources must not feed account-wide nuke enumeration.
377
- Effect.succeed([]),
378
- read: ({ output }) => output === undefined
379
- ? Effect.succeed(undefined)
380
- : fetchSubmission(http, options, baseUrl, output.id).pipe(Effect.map((result) => toDocuSealSubmissionAttributes(baseUrl, result)), Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined))),
392
+ list: () => Effect.succeed([]),
393
+ read: Effect.fn(function* ({ output }) {
394
+ if (output === undefined)
395
+ return undefined;
396
+ const options = yield* credentials;
397
+ const baseUrl = docuSealBaseUrl(options);
398
+ return yield* fetchSubmission(http, options, baseUrl, output.id).pipe(Effect.map((result) => toDocuSealSubmissionAttributes(baseUrl, result)), Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined)));
399
+ }),
381
400
  reconcile: Effect.fn(function* ({ news, output }) {
382
401
  if (output !== undefined)
383
402
  return output;
403
+ const options = yield* credentials;
404
+ const baseUrl = docuSealBaseUrl(options);
384
405
  const input = yield* docusealSignatureRequestInputFromResourceProps(news);
385
406
  return yield* createSubmission(http, options, baseUrl, input);
386
407
  }),
387
- delete: ({ output }) => deleteSubmission(http, options, baseUrl, output.id),
408
+ delete: Effect.fn(function* ({ output }) {
409
+ const options = yield* credentials;
410
+ const baseUrl = docuSealBaseUrl(options);
411
+ return yield* deleteSubmission(http, options, baseUrl, output.id);
412
+ }),
388
413
  });
389
414
  }));
390
- export class DocuSealProviders extends Provider.ProviderCollection()(DOCUSEAL_PROVIDER_COLLECTION_ID) {
415
+ class DocuSealProviders extends Provider.ProviderCollection()(DOCUSEAL_PROVIDER_COLLECTION_ID) {
391
416
  }
392
- export const providers = (options) => Layer.effect(DocuSealProviders, Provider.collection([DocuSealSignatureRequest])).pipe(Layer.provide(DocuSealSignatureRequestProvider()), Layer.provide(docuSealCredentialsLayer(options)));
417
+ export const providers = (options) => Layer.effect(DocuSealProviders, Provider.collection([DocuSealSignatureRequest])).pipe(Layer.provide(Layer.fresh(docuSealSignatureRequestProvider)), Layer.provide(docuSealCredentialsLayer(options)));
393
418
  export const getDocuSealSignatureRequest = (options, id) => Effect.gen(function* () {
394
419
  const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
395
420
  code: SignatureKitErrorCodeValue.invalidInput,
@@ -439,3 +464,18 @@ export const downloadDocuSealSignedDocument = (options, id) => Effect.gen(functi
439
464
  const http = yield* SignatureHttpClient;
440
465
  return yield* downloadDocumentFromSubmission(http, valid, docuSealBaseUrl(valid), id);
441
466
  });
467
+ export const waitForDocuSealSignatureRequest = Effect.fn(function* (options, id, pollInterval) {
468
+ const interval = yield* Schema.decodeUnknownEffect(Schema.Duration.check(Schema.makeFilter((value) => Duration.isFinite(value) && Duration.isPositive(value))))(pollInterval).pipe(Effect.mapError((issue) => new SignatureKitError({
469
+ code: SignatureKitErrorCodeValue.invalidInput,
470
+ retryable: false,
471
+ provider: PROVIDER,
472
+ operation: SignatureKitOperationValue.schemaDecode,
473
+ schemaName: "DocuSealPollInterval",
474
+ issueMessage: String(issue),
475
+ reason: "Polling requires a positive, finite interval.",
476
+ })));
477
+ return yield* getDocuSealSignatureRequest(options, id).pipe(Effect.repeat({
478
+ while: (request) => Match.value(request.state).pipe(Match.whenOr("draft", "sent", () => true), Match.whenOr("completed", "cancelled", "deleted", "declined", "expired", () => false), Match.exhaustive),
479
+ schedule: Schedule.spaced(interval),
480
+ }));
481
+ });
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@signature-kit/docuseal",
3
- "version": "0.3.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.1.0",
33
- "alchemy": "2.0.0-beta.57",
34
- "effect": "4.0.0-beta.86"
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": "npm pack --dry-run --json",
43
+ "command": "bun pm pack --dry-run",
42
44
  "cwd": "{projectRoot}"
43
45
  }
44
46
  },