@signature-kit/docuseal 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
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
+
23
+ ## 0.3.0
24
+
25
+ - DocuSeal now owns its submission props, attributes, state schema, schema names,
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.
29
+ - Refuse signed-document downloads before a submission is completed, returning a
30
+ typed `unsupportedOperation` instead of silently returning the unsigned source
31
+ document.
32
+ - Advertise `downloadUrl` only for completed submissions, because draft
33
+ submission document URLs can point at unsigned bytes.
34
+ - Add offline local-HTTP-server coverage for DocuSeal provider behavior in the
35
+ default test suite.
36
+
37
+ Breaking: request props now use `DocuSealSubmissionProps` with `contentBase64`
38
+ documents, and `getDocuSealSignatureRequest` / `listDocuSealSignatureRequests`
39
+ return `DocuSealSubmissionAttributes` instead of core `RemoteSignature*` types.
40
+
3
41
  ## 0.2.0
4
42
 
5
43
  - Deduplicate submitter roles so recipients sharing a role are accepted by DocuSeal.
@@ -12,4 +50,4 @@
12
50
 
13
51
  - Initial npm-ready release for `@signature-kit/docuseal`.
14
52
  - Published package metadata, MIT license, README, and package-local changelog.
15
- - Ships alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and signed-document download.
53
+ - Ships an Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and signed-document download.
package/README.md CHANGED
@@ -1,24 +1,102 @@
1
1
  # @signature-kit/docuseal
2
2
 
3
- Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and signed-document download.
3
+ Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, listing, deletion, and completed-document download.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- bun add @signature-kit/docuseal effect alchemy
8
+ bun add @signature-kit/docuseal @signature-kit/http effect alchemy
9
9
  ```
10
10
 
11
- ## Exports
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
- - `@signature-kit/docuseal`
17
+ ## Public surface
14
18
 
15
- ## Runtime model
19
+ - `@signature-kit/docuseal` — DocuSeal submission/document/submitter schemas, `DocuSealSignatureRequest`, `providers`, `getDocuSealSignatureRequest`, `listDocuSealSignatureRequests`, `deleteDocuSealSignatureRequest`, and `downloadDocuSealSignedDocument`.
16
20
 
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.
21
+ Capability matrix:
18
22
 
19
- ## Version
23
+ | Capability | Supported |
24
+ | ---------------------------------- | --------------------------------------------------------------- |
25
+ | Create retained Alchemy submission | Yes |
26
+ | Get submission | Yes |
27
+ | List submissions | Yes |
28
+ | Cancel submission | No public cancel helper is exposed |
29
+ | Delete submission | Yes |
30
+ | Download signed document | Yes, only for completed submissions with provider document URLs |
20
31
 
21
- Current npm release line: `0.1.0`.
32
+ Retained-resource semantics: Alchemy `reconcile` creates once and returns cached output on subsequent plans; provider `list` returns `[]`; `nuke` is skipped. Create is a single submission POST, so there is no multi-step rollback sequence to compensate after a partial provider workflow.
33
+
34
+ ## Example
35
+
36
+ ```ts
37
+ import * as Alchemy from "alchemy";
38
+ import {
39
+ DocuSealSignatureRequest,
40
+ downloadDocuSealSignedDocument,
41
+ providers as docusealProviders,
42
+ type DocuSealProviderOptions,
43
+ } from "@signature-kit/docuseal";
44
+ import { signatureHttpClientLive } from "@signature-kit/http";
45
+ import { Effect, Layer, Redacted } from "effect";
46
+
47
+ declare const pdfBase64: string;
48
+ declare const apiKey: string;
49
+
50
+ const options: DocuSealProviderOptions = {
51
+ apiKey: Redacted.make(apiKey),
52
+ };
53
+
54
+ export default class Contracts extends Alchemy.Stack<Contracts>()(
55
+ "Contracts",
56
+ {
57
+ providers: Layer.merge(docusealProviders(options), signatureHttpClientLive),
58
+ state: Alchemy.inMemoryState(),
59
+ },
60
+ Effect.gen(function* () {
61
+ return yield* DocuSealSignatureRequest("service-agreement", {
62
+ title: "Service agreement",
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 downloadSigned = (id: string) =>
73
+ downloadDocuSealSignedDocument(options, id).pipe(Effect.provide(signatureHttpClientLive));
74
+ ```
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
+
95
+ ## Errors and i18n
96
+
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`.
98
+
99
+ Docs: <https://signaturekit.dev/en-US/docs/providers/docuseal>.
22
100
 
23
101
  ## License
24
102
 
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
- import { Context, Effect, Layer, Redacted, Schema } from "effect";
5
+ import { Duration, Effect, Layer, Redacted, Schema } from "effect";
6
+ export declare const DocuSealProviderId = "docuseal";
7
+ export declare const DocuSealSubmissionStateSchema: Schema.Literals<readonly ["draft", "sent", "completed", "cancelled", "deleted", "declined", "expired"]>;
8
+ export type DocuSealSubmissionState = (typeof DocuSealSubmissionStateSchema)["Type"];
9
+ export declare const DocuSealSubmissionDocumentSchema: Schema.Struct<{
10
+ readonly fileName: Schema.NonEmptyString;
11
+ readonly mimeType: Schema.Literal<"application/pdf">;
12
+ readonly content: Schema.Uint8Array;
13
+ }>;
14
+ export type DocuSealSubmissionDocument = (typeof DocuSealSubmissionDocumentSchema)["Type"];
15
+ export declare const DocuSealSubmissionDocumentPropsSchema: Schema.Struct<{
16
+ readonly fileName: Schema.NonEmptyString;
17
+ readonly mimeType: Schema.Literal<"application/pdf">;
18
+ readonly contentBase64: Schema.ConstraintDecoder<string, never>;
19
+ }>;
20
+ export type DocuSealSubmissionDocumentProps = (typeof DocuSealSubmissionDocumentPropsSchema)["Type"];
21
+ export declare const DocuSealSubmitterSchema: Schema.Struct<{
22
+ readonly name: Schema.NonEmptyString;
23
+ readonly email: Schema.NonEmptyString;
24
+ readonly role: Schema.optional<Schema.NonEmptyString>;
25
+ readonly routingOrder: Schema.optional<Schema.Finite>;
26
+ }>;
27
+ export type DocuSealSubmitter = (typeof DocuSealSubmitterSchema)["Type"];
28
+ export declare const DocuSealSubmissionInputSchema: Schema.Struct<{
29
+ readonly title: Schema.NonEmptyString;
30
+ readonly subject: Schema.optional<Schema.NonEmptyString>;
31
+ readonly message: Schema.optional<Schema.NonEmptyString>;
32
+ readonly documents: Schema.NonEmptyArray<Schema.Struct<{
33
+ readonly fileName: Schema.NonEmptyString;
34
+ readonly mimeType: Schema.Literal<"application/pdf">;
35
+ readonly content: Schema.Uint8Array;
36
+ }>>;
37
+ readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
38
+ readonly name: Schema.NonEmptyString;
39
+ readonly email: Schema.NonEmptyString;
40
+ readonly role: Schema.optional<Schema.NonEmptyString>;
41
+ readonly routingOrder: Schema.optional<Schema.Finite>;
42
+ }>>;
43
+ readonly send: Schema.optional<Schema.Boolean>;
44
+ readonly expiresAt: Schema.optional<Schema.Date>;
45
+ readonly redirectUrl: Schema.optional<Schema.NonEmptyString>;
46
+ }>;
47
+ export type DocuSealSubmissionInput = (typeof DocuSealSubmissionInputSchema)["Type"];
48
+ export declare const DocuSealSubmissionPropsSchema: Schema.Struct<{
49
+ readonly title: Schema.NonEmptyString;
50
+ readonly subject: Schema.optional<Schema.NonEmptyString>;
51
+ readonly message: Schema.optional<Schema.NonEmptyString>;
52
+ readonly documents: Schema.NonEmptyArray<Schema.Struct<{
53
+ readonly fileName: Schema.NonEmptyString;
54
+ readonly mimeType: Schema.Literal<"application/pdf">;
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.NonEmptyString>;
61
+ readonly routingOrder: Schema.optional<Schema.Finite>;
62
+ }>>;
63
+ readonly send: Schema.optional<Schema.Boolean>;
64
+ readonly expiresAt: Schema.optional<Schema.Date>;
65
+ readonly redirectUrl: Schema.optional<Schema.NonEmptyString>;
66
+ }>;
67
+ export type DocuSealSubmissionProps = (typeof DocuSealSubmissionPropsSchema)["Type"];
68
+ export declare const DocuSealSubmissionAttributesSchema: Schema.Struct<{
69
+ readonly provider: Schema.Literal<"docuseal">;
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 DocuSealSubmissionAttributes = (typeof DocuSealSubmissionAttributesSchema)["Type"];
7
78
  declare const DocuSealSubmittersOrderSchema: Schema.Literals<readonly ["preserved", "random"]>;
8
79
  export type DocuSealSubmittersOrder = (typeof DocuSealSubmittersOrderSchema)["Type"];
9
80
  export declare const DocuSealProviderOptionsSchema: Schema.Struct<{
@@ -13,25 +84,29 @@ export declare const DocuSealProviderOptionsSchema: Schema.Struct<{
13
84
  readonly submittersOrder: Schema.optional<Schema.Literals<readonly ["preserved", "random"]>>;
14
85
  }>;
15
86
  export type DocuSealProviderOptions = (typeof DocuSealProviderOptionsSchema)["Type"];
16
- export type DocuSealSignatureRequest = Resource<"SignatureKit.DocuSealSignatureRequest", RemoteSignatureRequestProps, RemoteSignatureRequest>;
87
+ export type DocuSealSignatureRequest = Resource<"SignatureKit.DocuSealSignatureRequest", DocuSealSubmissionProps, DocuSealSubmissionAttributes>;
17
88
  export declare const DocuSealSignatureRequest: import("alchemy").ResourceClass<DocuSealSignatureRequest>;
18
- declare const DocuSealCredentials_base: Context.ServiceClass<DocuSealCredentials, "@signature-kit/docuseal/Credentials", {
19
- readonly apiKey: Redacted.Redacted<string>;
20
- readonly baseUrl?: string | undefined;
21
- readonly sendSms?: boolean | undefined;
22
- readonly submittersOrder?: "preserved" | "random" | undefined;
23
- }>;
24
- export declare class DocuSealCredentials extends DocuSealCredentials_base {
25
- }
26
- export declare const docuSealCredentialsLayer: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealCredentials, SignatureKitError>;
27
- export declare const DocuSealSignatureRequestProvider: () => Layer.Layer<Provider.Provider<DocuSealSignatureRequest>, never, DocuSealCredentials | SignatureHttpClient>;
28
89
  declare const DocuSealProviders_base: Provider.ProviderCollection<DocuSealProviders, "@signature-kit/docuseal/Providers">;
29
- export declare class DocuSealProviders extends DocuSealProviders_base {
90
+ declare class DocuSealProviders extends DocuSealProviders_base {
30
91
  }
31
- export declare const providers: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealProviders, SignatureKitError, SignatureHttpClient>;
32
- export declare const getDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<RemoteSignatureRequest, SignatureKitError, SignatureHttpClient>;
33
- export declare const listDocuSealSignatureRequests: (options: DocuSealProviderOptions) => Effect.Effect<readonly RemoteSignatureRequest[], SignatureKitError, SignatureHttpClient>;
92
+ export declare const providers: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealProviders, never, SignatureHttpClient>;
93
+ export declare const getDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<DocuSealSubmissionAttributes, SignatureKitError, SignatureHttpClient>;
94
+ export declare const listDocuSealSignatureRequests: (options: DocuSealProviderOptions) => Effect.Effect<readonly DocuSealSubmissionAttributes[], SignatureKitError, SignatureHttpClient>;
34
95
  export declare const deleteDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
35
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>;
36
111
  export {};
37
112
  //# sourceMappingURL=index.d.ts.map
@@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,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,10 +1,114 @@
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";
1
+ import { base64ToBytes, bytesToBase64 } from "@signature-kit/crypto/base64";
2
+ import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, redactedStringSchema, } from "@signature-kit/signatures";
3
+ import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/http";
4
4
  import { Resource } from "alchemy";
5
5
  import * as Provider from "alchemy/Provider";
6
- import { Context, Effect, Layer, Option, Redacted, Schema, Stream } from "effect";
7
- const PROVIDER = "docuseal";
6
+ import { Context, Duration, Effect, Layer, Match, Option, Redacted, Schedule, Schema, Stream, } from "effect";
7
+ const DocuSealSchemaName = {
8
+ providerOptions: "DocuSealProviderOptions",
9
+ signatureRequestProps: "DocuSealSubmissionProps",
10
+ submissionResult: "DocuSealSubmissionResult",
11
+ submissionsResult: "DocuSealSubmissionsResult",
12
+ submissionDocumentsResult: "DocuSealSubmissionDocumentsResult",
13
+ };
14
+ const DocuSealOperation = {
15
+ create: "docuseal.create",
16
+ download: "docuseal.download",
17
+ };
18
+ const base64String = Schema.String.check(Schema.isBase64());
19
+ export const DocuSealProviderId = "docuseal";
20
+ const PROVIDER = DocuSealProviderId;
21
+ export const DocuSealSubmissionStateSchema = Schema.Literals([
22
+ "draft",
23
+ "sent",
24
+ "completed",
25
+ "cancelled",
26
+ "deleted",
27
+ "declined",
28
+ "expired",
29
+ ]);
30
+ export const DocuSealSubmissionDocumentSchema = Schema.Struct({
31
+ fileName: Schema.NonEmptyString,
32
+ mimeType: Schema.Literal("application/pdf"),
33
+ content: Schema.Uint8Array,
34
+ });
35
+ export const DocuSealSubmissionDocumentPropsSchema = Schema.Struct({
36
+ fileName: Schema.NonEmptyString,
37
+ mimeType: Schema.Literal("application/pdf"),
38
+ contentBase64: base64String,
39
+ });
40
+ export const DocuSealSubmitterSchema = Schema.Struct({
41
+ name: Schema.NonEmptyString,
42
+ email: Schema.NonEmptyString,
43
+ role: Schema.optional(Schema.NonEmptyString),
44
+ routingOrder: Schema.optional(Schema.Finite),
45
+ });
46
+ export const DocuSealSubmissionInputSchema = Schema.Struct({
47
+ title: Schema.NonEmptyString,
48
+ subject: Schema.optional(Schema.NonEmptyString),
49
+ message: Schema.optional(Schema.NonEmptyString),
50
+ documents: Schema.NonEmptyArray(DocuSealSubmissionDocumentSchema),
51
+ recipients: Schema.NonEmptyArray(DocuSealSubmitterSchema),
52
+ send: Schema.optional(Schema.Boolean),
53
+ expiresAt: Schema.optional(Schema.Date),
54
+ redirectUrl: Schema.optional(Schema.NonEmptyString),
55
+ });
56
+ export const DocuSealSubmissionPropsSchema = Schema.Struct({
57
+ title: Schema.NonEmptyString,
58
+ subject: Schema.optional(Schema.NonEmptyString),
59
+ message: Schema.optional(Schema.NonEmptyString),
60
+ documents: Schema.NonEmptyArray(DocuSealSubmissionDocumentPropsSchema),
61
+ recipients: Schema.NonEmptyArray(DocuSealSubmitterSchema),
62
+ send: Schema.optional(Schema.Boolean),
63
+ expiresAt: Schema.optional(Schema.Date),
64
+ redirectUrl: Schema.optional(Schema.NonEmptyString),
65
+ });
66
+ export const DocuSealSubmissionAttributesSchema = Schema.Struct({
67
+ provider: Schema.Literal(PROVIDER),
68
+ id: Schema.NonEmptyString,
69
+ state: DocuSealSubmissionStateSchema,
70
+ providerStatus: Schema.optional(Schema.String),
71
+ signingUrl: Schema.optional(Schema.String),
72
+ detailsUrl: Schema.optional(Schema.String),
73
+ downloadUrl: Schema.optional(Schema.String),
74
+ });
75
+ const docusealSignatureRequestNoopDiff = { action: "noop" };
76
+ const docusealSignatureRequestDiff = ({ olds, }) => Effect.succeed(olds === undefined ? undefined : docusealSignatureRequestNoopDiff);
77
+ const docusealSignatureRequestInputFromProps = Effect.fn(function* (props) {
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
+ ];
93
+ return {
94
+ title: props.title,
95
+ documents,
96
+ recipients: props.recipients,
97
+ ...(props.subject === undefined ? {} : { subject: props.subject }),
98
+ ...(props.message === undefined ? {} : { message: props.message }),
99
+ ...(props.send === undefined ? {} : { send: props.send }),
100
+ ...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
101
+ ...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
102
+ };
103
+ });
104
+ const docusealSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(DocuSealSubmissionPropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
105
+ code: SignatureKitErrorCodeValue.invalidInput,
106
+ retryable: false,
107
+ provider: PROVIDER,
108
+ operation: SignatureKitOperationValue.schemaDecode,
109
+ schemaName: DocuSealSchemaName.signatureRequestProps,
110
+ issueMessage: String(issue),
111
+ })), Effect.flatMap(docusealSignatureRequestInputFromProps));
8
112
  const DOCUSEAL_PROVIDER_COLLECTION_ID = "@signature-kit/docuseal/Providers";
9
113
  const DEFAULT_BASE_URL = "https://api.docuseal.com";
10
114
  const DocuSealSubmittersOrderSchema = Schema.Literals(["preserved", "random"]);
@@ -14,7 +118,7 @@ export const DocuSealProviderOptionsSchema = Schema.Struct({
14
118
  sendSms: Schema.optional(Schema.Boolean),
15
119
  submittersOrder: Schema.optional(DocuSealSubmittersOrderSchema),
16
120
  });
17
- const DocuSealSubmissionIdSchema = Schema.Union([Schema.Number, Schema.NonEmptyString]);
121
+ const DocuSealSubmissionIdSchema = Schema.Union([Schema.Finite, Schema.NonEmptyString]);
18
122
  const DocuSealSubmitterLinkFields = {
19
123
  embed_src: Schema.optional(Schema.NullOr(Schema.String)),
20
124
  signing_url: Schema.optional(Schema.NullOr(Schema.String)),
@@ -54,32 +158,31 @@ const DocuSealSubmissionDocumentsResultSchema = Schema.Struct({
54
158
  })),
55
159
  });
56
160
  const DocuSealPaginationSchema = Schema.Struct({
57
- count: Schema.Number,
58
- next: Schema.NullOr(Schema.Number),
59
- prev: Schema.NullOr(Schema.Number),
161
+ count: Schema.Finite,
162
+ next: Schema.NullOr(Schema.Finite),
163
+ prev: Schema.NullOr(Schema.Finite),
60
164
  });
61
165
  const DocuSealSubmissionsResultSchema = Schema.Struct({
62
166
  data: Schema.Array(DocuSealSubmissionResultSchema),
63
167
  pagination: DocuSealPaginationSchema,
64
168
  });
65
169
  export const DocuSealSignatureRequest = Resource("SignatureKit.DocuSealSignatureRequest", { defaultRemovalPolicy: "retain" });
66
- export class DocuSealCredentials extends Context.Service()("@signature-kit/docuseal/Credentials") {
170
+ class DocuSealCredentials extends Context.Service()("@signature-kit/docuseal/Credentials") {
67
171
  }
68
- 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({
69
173
  code: SignatureKitErrorCodeValue.invalidInput,
70
174
  retryable: false,
71
175
  provider: PROVIDER,
72
176
  operation: SignatureKitOperationValue.schemaDecode,
73
- schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
177
+ schemaName: DocuSealSchemaName.providerOptions,
74
178
  issueMessage: String(issue),
75
- }))));
179
+ })))));
76
180
  const docuSealBaseUrl = (options) => options.baseUrl === undefined ? DEFAULT_BASE_URL : normalizedBaseUrl(options.baseUrl);
77
181
  const authHeaders = (options) => ({
78
182
  "X-Auth-Token": Redacted.value(options.apiKey),
79
183
  });
80
184
  const normalizeSubmissionId = (submissionId) => typeof submissionId === "string" ? submissionId : submissionId.toString();
81
- const normalizeSubmissionPathId = (submissionId) => encodeURIComponent(submissionId);
82
- const docuSealSubmissionUrl = (baseUrl, submissionId) => `${baseUrl}/submissions/${normalizeSubmissionPathId(submissionId)}`;
185
+ const docuSealSubmissionUrl = (baseUrl, submissionId) => `${baseUrl}/submissions/${encodeURIComponent(submissionId)}`;
83
186
  const docuSealSubmissionListUrl = (baseUrl, after) => {
84
187
  const url = new URL(`${baseUrl}/submissions`);
85
188
  url.searchParams.set("limit", "100");
@@ -87,30 +190,24 @@ const docuSealSubmissionListUrl = (baseUrl, after) => {
87
190
  url.searchParams.set("after", after.toString());
88
191
  return url.toString();
89
192
  };
90
- const docuSealSubmissionsNextUrl = (baseUrl, pagination) => pagination.next === null
91
- ? Option.none()
92
- : Option.some(docuSealSubmissionListUrl(baseUrl, pagination.next));
93
- const mapRemoteState = (status) => {
193
+ const DocuSealStatusSchema = Schema.Literals([
194
+ "draft",
195
+ "completed",
196
+ "declined",
197
+ "expired",
198
+ "deleted",
199
+ "archived",
200
+ "cancelled",
201
+ "canceled",
202
+ ]);
203
+ const isDocuSealStatus = Schema.is(DocuSealStatusSchema);
204
+ const docuSealSubmissionState = (status) => {
94
205
  if (status === undefined)
95
206
  return "sent";
96
- switch (status.toLowerCase()) {
97
- case "draft":
98
- return "draft";
99
- case "completed":
100
- return "completed";
101
- case "declined":
102
- return "declined";
103
- case "expired":
104
- return "expired";
105
- case "deleted":
106
- case "archived":
107
- return "deleted";
108
- case "cancelled":
109
- case "canceled":
110
- return "cancelled";
111
- default:
112
- return "sent";
113
- }
207
+ const normalized = status.toLowerCase();
208
+ if (!isDocuSealStatus(normalized))
209
+ return "sent";
210
+ return Match.value(normalized).pipe(Match.when("draft", () => "draft"), Match.when("completed", () => "completed"), Match.when("declined", () => "declined"), Match.when("expired", () => "expired"), Match.whenOr("deleted", "archived", () => "deleted"), Match.whenOr("cancelled", "canceled", () => "cancelled"), Match.orElse(() => "sent"));
114
211
  };
115
212
  const resolveSubmitterRoles = (recipients) => {
116
213
  const roleCounts = new Map();
@@ -128,14 +225,15 @@ const pickSigningUrl = (submission) => submission.submitters?.[0]?.embed_src ??
128
225
  const pickDownloadUrl = (submission) => submission.combined_document_url ??
129
226
  submission.documents?.[0]?.url ??
130
227
  submission.documents?.[0]?.download_url;
131
- const toRemoteSignatureRequest = (baseUrl, submission) => {
228
+ const toDocuSealSubmissionAttributes = (baseUrl, submission) => {
132
229
  const id = normalizeSubmissionId(submission.id);
133
230
  const signingUrl = pickSigningUrl(submission);
134
- const downloadUrl = pickDownloadUrl(submission);
231
+ const state = docuSealSubmissionState(submission.status);
232
+ const downloadUrl = state === "completed" ? pickDownloadUrl(submission) : undefined;
135
233
  return {
136
234
  provider: PROVIDER,
137
235
  id,
138
- state: mapRemoteState(submission.status),
236
+ state,
139
237
  detailsUrl: docuSealSubmissionUrl(baseUrl, id),
140
238
  ...(submission.status === undefined ? {} : { providerStatus: submission.status }),
141
239
  ...(signingUrl === undefined || signingUrl === null ? {} : { signingUrl }),
@@ -182,10 +280,10 @@ const createSubmission = (http, options, baseUrl, input) => {
182
280
  ...(input.subject === undefined ? {} : { subject: input.subject }),
183
281
  ...(input.message === undefined ? {} : { message: { body: input.message } }),
184
282
  }),
185
- }, DocuSealCreateSubmissionResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionResult)
283
+ }, DocuSealCreateSubmissionResultSchema, DocuSealSchemaName.submissionResult)
186
284
  .pipe(Effect.map((result) => {
187
285
  if ("id" in result) {
188
- const mapped = toRemoteSignatureRequest(baseUrl, result);
286
+ const mapped = toDocuSealSubmissionAttributes(baseUrl, result);
189
287
  const providerStatus = result.status ?? result.submitters?.[0]?.status;
190
288
  return {
191
289
  ...mapped,
@@ -206,24 +304,44 @@ const createSubmission = (http, options, baseUrl, input) => {
206
304
  };
207
305
  }));
208
306
  };
209
- const submissionsFromListResult = (result) => result.data;
210
- const listSubmissions = (http, options, baseUrl) => Stream.paginate(docuSealSubmissionListUrl(baseUrl), (url) => http
211
- .requestJson({
212
- provider: PROVIDER,
213
- method: "GET",
214
- url,
215
- headers: authHeaders(options),
216
- }, DocuSealSubmissionsResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionsResult)
217
- .pipe(Effect.map((result) => [
218
- submissionsFromListResult(result).map((submission) => toRemoteSignatureRequest(baseUrl, submission)),
219
- docuSealSubmissionsNextUrl(baseUrl, result.pagination),
220
- ]))).pipe(Stream.runCollect, Effect.map((requests) => requests.flat()));
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);
221
339
  const fetchSubmission = (http, options, baseUrl, id) => http.requestJson({
222
340
  provider: PROVIDER,
223
341
  method: "GET",
224
342
  url: docuSealSubmissionUrl(baseUrl, id),
225
343
  headers: authHeaders(options),
226
- }, DocuSealSubmissionResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionResult);
344
+ }, DocuSealSubmissionResultSchema, DocuSealSchemaName.submissionResult);
227
345
  const deleteSubmission = (http, options, baseUrl, id) => http
228
346
  .requestVoid({
229
347
  provider: PROVIDER,
@@ -237,8 +355,17 @@ const fetchSubmissionDocuments = (http, options, baseUrl, id) => http.requestJso
237
355
  method: "GET",
238
356
  url: `${docuSealSubmissionUrl(baseUrl, id)}/documents?merge=true`,
239
357
  headers: authHeaders(options),
240
- }, DocuSealSubmissionDocumentsResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionDocumentsResult);
358
+ }, DocuSealSubmissionDocumentsResultSchema, DocuSealSchemaName.submissionDocumentsResult);
241
359
  const downloadDocumentFromSubmission = (http, options, baseUrl, id) => fetchSubmission(http, options, baseUrl, id).pipe(Effect.flatMap((submission) => {
360
+ if (docuSealSubmissionState(submission.status) !== "completed") {
361
+ return Effect.fail(new SignatureKitError({
362
+ code: SignatureKitErrorCodeValue.unsupportedOperation,
363
+ retryable: false,
364
+ provider: PROVIDER,
365
+ operation: DocuSealOperation.download,
366
+ reason: `DocuSeal submission ${id} is not completed yet (status: ${submission.status ?? "unknown"}); the signed document does not exist.`,
367
+ }));
368
+ }
242
369
  const downloadUrl = pickDownloadUrl(submission);
243
370
  if (downloadUrl !== undefined && downloadUrl !== null)
244
371
  return requestBytesFromUrl(http, downloadUrl);
@@ -249,47 +376,57 @@ const downloadDocumentFromSubmission = (http, options, baseUrl, id) => fetchSubm
249
376
  code: SignatureKitErrorCodeValue.responseShape,
250
377
  retryable: false,
251
378
  provider: PROVIDER,
252
- operation: SignatureKitOperationValue.remoteDownload,
379
+ operation: DocuSealOperation.download,
253
380
  reason: `DocuSeal submission ${id} has no downloadable document URL.`,
254
381
  }));
255
382
  }
256
383
  return requestBytesFromUrl(http, url);
257
384
  }));
258
385
  }));
259
- export const DocuSealSignatureRequestProvider = () => Provider.effect(DocuSealSignatureRequest, Effect.gen(function* () {
260
- const options = yield* DocuSealCredentials;
386
+ const docuSealSignatureRequestProvider = Provider.effect(DocuSealSignatureRequest, Effect.gen(function* () {
387
+ const credentials = yield* DocuSealCredentials;
261
388
  const http = yield* SignatureHttpClient;
262
- const baseUrl = docuSealBaseUrl(options);
263
389
  return DocuSealSignatureRequest.Provider.of({
264
- diff: ({ olds }) => Effect.succeed(olds === undefined ? undefined : { action: "noop" }),
265
- list: () => listSubmissions(http, options, baseUrl),
266
- read: ({ output }) => output === undefined
267
- ? Effect.succeed(undefined)
268
- : fetchSubmission(http, options, baseUrl, output.id).pipe(Effect.map((result) => toRemoteSignatureRequest(baseUrl, result)), Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined))),
390
+ nuke: { skip: true },
391
+ diff: docusealSignatureRequestDiff,
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
+ }),
269
400
  reconcile: Effect.fn(function* ({ news, output }) {
270
401
  if (output !== undefined)
271
402
  return output;
272
- const input = yield* remoteSignatureInputFromResourceProps(PROVIDER, news);
403
+ const options = yield* credentials;
404
+ const baseUrl = docuSealBaseUrl(options);
405
+ const input = yield* docusealSignatureRequestInputFromResourceProps(news);
273
406
  return yield* createSubmission(http, options, baseUrl, input);
274
407
  }),
275
- 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
+ }),
276
413
  });
277
414
  }));
278
- export class DocuSealProviders extends Provider.ProviderCollection()(DOCUSEAL_PROVIDER_COLLECTION_ID) {
415
+ class DocuSealProviders extends Provider.ProviderCollection()(DOCUSEAL_PROVIDER_COLLECTION_ID) {
279
416
  }
280
- 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)));
281
418
  export const getDocuSealSignatureRequest = (options, id) => Effect.gen(function* () {
282
419
  const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
283
420
  code: SignatureKitErrorCodeValue.invalidInput,
284
421
  retryable: false,
285
422
  provider: PROVIDER,
286
423
  operation: SignatureKitOperationValue.schemaDecode,
287
- schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
424
+ schemaName: DocuSealSchemaName.providerOptions,
288
425
  issueMessage: String(issue),
289
426
  })));
290
427
  const http = yield* SignatureHttpClient;
291
428
  const baseUrl = docuSealBaseUrl(valid);
292
- return yield* fetchSubmission(http, valid, baseUrl, id).pipe(Effect.map((result) => toRemoteSignatureRequest(baseUrl, result)));
429
+ return yield* fetchSubmission(http, valid, baseUrl, id).pipe(Effect.map((result) => toDocuSealSubmissionAttributes(baseUrl, result)));
293
430
  });
294
431
  export const listDocuSealSignatureRequests = (options) => Effect.gen(function* () {
295
432
  const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
@@ -297,7 +434,7 @@ export const listDocuSealSignatureRequests = (options) => Effect.gen(function* (
297
434
  retryable: false,
298
435
  provider: PROVIDER,
299
436
  operation: SignatureKitOperationValue.schemaDecode,
300
- schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
437
+ schemaName: DocuSealSchemaName.providerOptions,
301
438
  issueMessage: String(issue),
302
439
  })));
303
440
  const http = yield* SignatureHttpClient;
@@ -309,7 +446,7 @@ export const deleteDocuSealSignatureRequest = (options, id) => Effect.gen(functi
309
446
  retryable: false,
310
447
  provider: PROVIDER,
311
448
  operation: SignatureKitOperationValue.schemaDecode,
312
- schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
449
+ schemaName: DocuSealSchemaName.providerOptions,
313
450
  issueMessage: String(issue),
314
451
  })));
315
452
  const http = yield* SignatureHttpClient;
@@ -321,9 +458,24 @@ export const downloadDocuSealSignedDocument = (options, id) => Effect.gen(functi
321
458
  retryable: false,
322
459
  provider: PROVIDER,
323
460
  operation: SignatureKitOperationValue.schemaDecode,
324
- schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
461
+ schemaName: DocuSealSchemaName.providerOptions,
325
462
  issueMessage: String(issue),
326
463
  })));
327
464
  const http = yield* SignatureHttpClient;
328
465
  return yield* downloadDocumentFromSubmission(http, valid, docuSealBaseUrl(valid), id);
329
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.2.0",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Licitei/signature-kit.git"
8
+ },
5
9
  "files": [
6
10
  "dist",
7
11
  "README.md",
@@ -22,22 +26,21 @@
22
26
  "access": "public"
23
27
  },
24
28
  "scripts": {
25
- "build": "tsc -b tsconfig.json",
26
- "typecheck": "tsc -p tsconfig.json --noEmit",
27
29
  "test": "vitest run"
28
30
  },
29
31
  "dependencies": {
30
- "@signature-kit/core": "^0.2.0",
31
- "@signature-kit/crypto": "^0.2.0",
32
- "alchemy": "2.0.0-beta.57",
33
- "effect": "4.0.0-beta.86"
32
+ "@signature-kit/crypto": "^0.2.1",
33
+ "@signature-kit/http": "^0.1.0",
34
+ "@signature-kit/signatures": "^0.2.0",
35
+ "alchemy": "2.0.0-beta.83",
36
+ "effect": "4.0.5"
34
37
  },
35
38
  "nx": {
36
39
  "targets": {
37
40
  "npm-pack": {
38
41
  "executor": "nx:run-commands",
39
42
  "options": {
40
- "command": "npm pack --dry-run --json",
43
+ "command": "bun pm pack --dry-run",
41
44
  "cwd": "{projectRoot}"
42
45
  }
43
46
  },