@signature-kit/docuseal 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +63 -8
- package/dist/index.d.ts +77 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +265 -127
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- DocuSeal now owns its submission props, attributes, state schema, schema names,
|
|
6
|
+
and retained no-op diff instead of using core remote-signature contracts.
|
|
7
|
+
- Refuse signed-document downloads before a submission is completed, returning a
|
|
8
|
+
typed `unsupportedOperation` instead of silently returning the unsigned source
|
|
9
|
+
document.
|
|
10
|
+
- Advertise `downloadUrl` only for completed submissions, because draft
|
|
11
|
+
submission document URLs can point at unsigned bytes.
|
|
12
|
+
- Add offline local-HTTP-server coverage for DocuSeal provider behavior in the
|
|
13
|
+
default test suite.
|
|
14
|
+
|
|
15
|
+
Breaking: request props now use `DocuSealSubmissionProps` with `contentBase64`
|
|
16
|
+
documents, and `getDocuSealSignatureRequest` / `listDocuSealSignatureRequests`
|
|
17
|
+
return `DocuSealSubmissionAttributes` instead of core `RemoteSignature*` types.
|
|
18
|
+
|
|
19
|
+
## 0.2.0
|
|
20
|
+
|
|
21
|
+
- Deduplicate submitter roles so recipients sharing a role are accepted by DocuSeal.
|
|
22
|
+
- Paginate list results.
|
|
23
|
+
- Total status mapping over exact literals instead of substring matching.
|
|
24
|
+
- Accept JSON `null` for optional URL fields (`combined_document_url`, `embed_src`, etc.) that
|
|
25
|
+
the real API returns for unsigned submissions, instead of failing response decode.
|
|
26
|
+
|
|
3
27
|
## 0.1.0
|
|
4
28
|
|
|
5
29
|
- Initial npm-ready release for `@signature-kit/docuseal`.
|
|
6
30
|
- Published package metadata, MIT license, README, and package-local changelog.
|
|
7
|
-
- Ships
|
|
31
|
+
- Ships an Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and signed-document download.
|
package/README.md
CHANGED
|
@@ -1,24 +1,79 @@
|
|
|
1
1
|
# @signature-kit/docuseal
|
|
2
2
|
|
|
3
|
-
Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and
|
|
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
|
-
|
|
11
|
+
`effect` and `alchemy` are direct runtime dependencies. Provide `signatureHttpClientLive` at the stack boundary; `providers(options)` supplies only DocuSeal credentials and resource providers.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Public surface
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
- `@signature-kit/docuseal` — DocuSeal submission/document/submitter schemas, `DocuSealSignatureRequest`, `DocuSealProviders`, `providers`, `getDocuSealSignatureRequest`, `listDocuSealSignatureRequests`, `deleteDocuSealSignatureRequest`, and `downloadDocuSealSignedDocument`.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Capability matrix:
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
| Capability | Supported |
|
|
20
|
+
| ---------------------------------- | --------------------------------------------------------------- |
|
|
21
|
+
| Create retained Alchemy submission | Yes |
|
|
22
|
+
| Get submission | Yes |
|
|
23
|
+
| List submissions | Yes |
|
|
24
|
+
| Cancel submission | No public cancel helper is exposed |
|
|
25
|
+
| Delete submission | Yes |
|
|
26
|
+
| Download signed document | Yes, only for completed submissions with provider document URLs |
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
## Example
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import * as Alchemy from "alchemy";
|
|
34
|
+
import {
|
|
35
|
+
DocuSealSignatureRequest,
|
|
36
|
+
downloadDocuSealSignedDocument,
|
|
37
|
+
providers as docusealProviders,
|
|
38
|
+
type DocuSealProviderOptions,
|
|
39
|
+
} from "@signature-kit/docuseal";
|
|
40
|
+
import { signatureHttpClientLive } from "@signature-kit/http";
|
|
41
|
+
import { Effect, Layer, Redacted } from "effect";
|
|
42
|
+
|
|
43
|
+
declare const pdfBase64: string;
|
|
44
|
+
declare const apiKey: string;
|
|
45
|
+
|
|
46
|
+
const options: DocuSealProviderOptions = {
|
|
47
|
+
apiKey: Redacted.make(apiKey),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default class Contracts extends Alchemy.Stack<Contracts>()(
|
|
51
|
+
"Contracts",
|
|
52
|
+
{
|
|
53
|
+
providers: Layer.merge(docusealProviders(options), signatureHttpClientLive),
|
|
54
|
+
state: Alchemy.inMemoryState(),
|
|
55
|
+
},
|
|
56
|
+
Effect.gen(function* () {
|
|
57
|
+
return yield* DocuSealSignatureRequest("service-agreement", {
|
|
58
|
+
title: "Service agreement",
|
|
59
|
+
documents: [
|
|
60
|
+
{ fileName: "contract.pdf", mimeType: "application/pdf", contentBase64: pdfBase64 },
|
|
61
|
+
],
|
|
62
|
+
recipients: [{ name: "Ada Lovelace", email: "ada@example.com", role: "signer" }],
|
|
63
|
+
send: true,
|
|
64
|
+
});
|
|
65
|
+
}),
|
|
66
|
+
) {}
|
|
67
|
+
|
|
68
|
+
export const downloadSigned = (id: string) =>
|
|
69
|
+
downloadDocuSealSignedDocument(options, id).pipe(Effect.provide(signatureHttpClientLive));
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Errors and i18n
|
|
73
|
+
|
|
74
|
+
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`.
|
|
75
|
+
|
|
76
|
+
Docs: <https://signaturekit.dev/en-US/docs/providers/docuseal>.
|
|
22
77
|
|
|
23
78
|
## License
|
|
24
79
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,80 @@
|
|
|
1
|
-
import { SignatureKitError } from "@signature-kit/
|
|
2
|
-
import
|
|
3
|
-
import { SignatureHttpClient } from "@signature-kit/core/http";
|
|
1
|
+
import { SignatureKitError } from "@signature-kit/signatures";
|
|
2
|
+
import { SignatureHttpClient } from "@signature-kit/http";
|
|
4
3
|
import { Resource } from "alchemy";
|
|
5
4
|
import * as Provider from "alchemy/Provider";
|
|
6
5
|
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
6
|
+
export declare const 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.NonEmptyString;
|
|
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.NonEmptyString;
|
|
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.Number>;
|
|
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.NonEmptyString;
|
|
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.Number>;
|
|
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.NonEmptyString;
|
|
55
|
+
readonly contentBase64: Schema.ConstraintDecoder<string, never>;
|
|
56
|
+
}>>;
|
|
57
|
+
readonly recipients: Schema.NonEmptyArray<Schema.Struct<{
|
|
58
|
+
readonly name: Schema.NonEmptyString;
|
|
59
|
+
readonly email: Schema.NonEmptyString;
|
|
60
|
+
readonly role: Schema.optional<Schema.NonEmptyString>;
|
|
61
|
+
readonly routingOrder: Schema.optional<Schema.Number>;
|
|
62
|
+
}>>;
|
|
63
|
+
readonly send: Schema.optional<Schema.Boolean>;
|
|
64
|
+
readonly expiresAt: Schema.optional<Schema.Date>;
|
|
65
|
+
readonly redirectUrl: Schema.optional<Schema.NonEmptyString>;
|
|
66
|
+
}>;
|
|
67
|
+
export type 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,7 +84,7 @@ 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",
|
|
87
|
+
export type DocuSealSignatureRequest = Resource<"SignatureKit.DocuSealSignatureRequest", DocuSealSubmissionProps, DocuSealSubmissionAttributes>;
|
|
17
88
|
export declare const DocuSealSignatureRequest: import("alchemy").ResourceClass<DocuSealSignatureRequest>;
|
|
18
89
|
declare const DocuSealCredentials_base: Context.ServiceClass<DocuSealCredentials, "@signature-kit/docuseal/Credentials", {
|
|
19
90
|
readonly apiKey: Redacted.Redacted<string>;
|
|
@@ -29,8 +100,8 @@ declare const DocuSealProviders_base: Provider.ProviderCollection<DocuSealProvid
|
|
|
29
100
|
export declare class DocuSealProviders extends DocuSealProviders_base {
|
|
30
101
|
}
|
|
31
102
|
export declare const providers: (options: DocuSealProviderOptions) => Layer.Layer<DocuSealProviders, SignatureKitError, SignatureHttpClient>;
|
|
32
|
-
export declare const getDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<
|
|
33
|
-
export declare const listDocuSealSignatureRequests: (options: DocuSealProviderOptions) => Effect.Effect<readonly
|
|
103
|
+
export declare const getDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<DocuSealSubmissionAttributes, SignatureKitError, SignatureHttpClient>;
|
|
104
|
+
export declare const listDocuSealSignatureRequests: (options: DocuSealProviderOptions) => Effect.Effect<readonly DocuSealSubmissionAttributes[], SignatureKitError, SignatureHttpClient>;
|
|
34
105
|
export declare const deleteDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
35
106
|
export declare const downloadDocuSealSignedDocument: (options: DocuSealProviderOptions, id: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
|
|
36
107
|
export {};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,111 @@
|
|
|
1
1
|
import { bytesToBase64 } from "@signature-kit/crypto/base64";
|
|
2
|
-
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue,
|
|
3
|
-
import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/
|
|
2
|
+
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, redactedStringSchema, } from "@signature-kit/signatures";
|
|
3
|
+
import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/http";
|
|
4
4
|
import { Resource } from "alchemy";
|
|
5
5
|
import * as Provider from "alchemy/Provider";
|
|
6
|
-
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
7
|
-
const
|
|
6
|
+
import { Context, Effect, Layer, Match, Option, Redacted, 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.NonEmptyString,
|
|
33
|
+
content: Schema.Uint8Array,
|
|
34
|
+
});
|
|
35
|
+
export const DocuSealSubmissionDocumentPropsSchema = Schema.Struct({
|
|
36
|
+
fileName: Schema.NonEmptyString,
|
|
37
|
+
mimeType: Schema.NonEmptyString,
|
|
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.Number),
|
|
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 = (props) => {
|
|
78
|
+
const [firstDocument, ...restDocuments] = props.documents;
|
|
79
|
+
return {
|
|
80
|
+
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
|
+
],
|
|
93
|
+
recipients: props.recipients,
|
|
94
|
+
...(props.subject === undefined ? {} : { subject: props.subject }),
|
|
95
|
+
...(props.message === undefined ? {} : { message: props.message }),
|
|
96
|
+
...(props.send === undefined ? {} : { send: props.send }),
|
|
97
|
+
...(props.expiresAt === undefined ? {} : { expiresAt: props.expiresAt }),
|
|
98
|
+
...(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl }),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const docusealSignatureRequestInputFromResourceProps = (props) => Schema.decodeUnknownEffect(DocuSealSubmissionPropsSchema)(props).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
102
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
103
|
+
retryable: false,
|
|
104
|
+
provider: PROVIDER,
|
|
105
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
106
|
+
schemaName: DocuSealSchemaName.signatureRequestProps,
|
|
107
|
+
issueMessage: String(issue),
|
|
108
|
+
})), Effect.map(docusealSignatureRequestInputFromProps));
|
|
8
109
|
const DOCUSEAL_PROVIDER_COLLECTION_ID = "@signature-kit/docuseal/Providers";
|
|
9
110
|
const DEFAULT_BASE_URL = "https://api.docuseal.com";
|
|
10
111
|
const DocuSealSubmittersOrderSchema = Schema.Literals(["preserved", "random"]);
|
|
@@ -16,10 +117,10 @@ export const DocuSealProviderOptionsSchema = Schema.Struct({
|
|
|
16
117
|
});
|
|
17
118
|
const DocuSealSubmissionIdSchema = Schema.Union([Schema.Number, Schema.NonEmptyString]);
|
|
18
119
|
const DocuSealSubmitterLinkFields = {
|
|
19
|
-
embed_src: Schema.optional(Schema.String),
|
|
20
|
-
signing_url: Schema.optional(Schema.String),
|
|
21
|
-
sign_url: Schema.optional(Schema.String),
|
|
22
|
-
url: Schema.optional(Schema.String),
|
|
120
|
+
embed_src: Schema.optional(Schema.NullOr(Schema.String)),
|
|
121
|
+
signing_url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
122
|
+
sign_url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
123
|
+
url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
23
124
|
};
|
|
24
125
|
const DocuSealCreateSubmitterResultSchema = Schema.Struct({
|
|
25
126
|
submission_id: DocuSealSubmissionIdSchema,
|
|
@@ -29,18 +130,18 @@ const DocuSealCreateSubmitterResultSchema = Schema.Struct({
|
|
|
29
130
|
const DocuSealSubmitterResultSchema = Schema.Struct({
|
|
30
131
|
status: Schema.optional(Schema.String),
|
|
31
132
|
...DocuSealSubmitterLinkFields,
|
|
32
|
-
download_url: Schema.optional(Schema.String),
|
|
133
|
+
download_url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
33
134
|
});
|
|
34
135
|
const DocuSealSubmissionResultSchema = Schema.Struct({
|
|
35
136
|
id: DocuSealSubmissionIdSchema,
|
|
36
137
|
status: Schema.optional(Schema.String),
|
|
37
138
|
submitters: Schema.optional(Schema.Array(DocuSealSubmitterResultSchema)),
|
|
38
|
-
combined_document_url: Schema.optional(Schema.String),
|
|
139
|
+
combined_document_url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
39
140
|
documents: Schema.optional(Schema.Array(Schema.Struct({
|
|
40
141
|
id: Schema.optional(DocuSealSubmissionIdSchema),
|
|
41
142
|
name: Schema.optional(Schema.String),
|
|
42
|
-
url: Schema.optional(Schema.String),
|
|
43
|
-
download_url: Schema.optional(Schema.String),
|
|
143
|
+
url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
144
|
+
download_url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
44
145
|
}))),
|
|
45
146
|
});
|
|
46
147
|
const DocuSealCreateSubmissionResultSchema = Schema.Union([
|
|
@@ -49,18 +150,19 @@ const DocuSealCreateSubmissionResultSchema = Schema.Union([
|
|
|
49
150
|
]);
|
|
50
151
|
const DocuSealSubmissionDocumentsResultSchema = Schema.Struct({
|
|
51
152
|
documents: Schema.Array(Schema.Struct({
|
|
52
|
-
url: Schema.optional(Schema.String),
|
|
53
|
-
download_url: Schema.optional(Schema.String),
|
|
153
|
+
url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
154
|
+
download_url: Schema.optional(Schema.NullOr(Schema.String)),
|
|
54
155
|
})),
|
|
55
156
|
});
|
|
56
|
-
const
|
|
57
|
-
Schema.
|
|
58
|
-
Schema.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
157
|
+
const DocuSealPaginationSchema = Schema.Struct({
|
|
158
|
+
count: Schema.Number,
|
|
159
|
+
next: Schema.NullOr(Schema.Number),
|
|
160
|
+
prev: Schema.NullOr(Schema.Number),
|
|
161
|
+
});
|
|
162
|
+
const DocuSealSubmissionsResultSchema = Schema.Struct({
|
|
163
|
+
data: Schema.Array(DocuSealSubmissionResultSchema),
|
|
164
|
+
pagination: DocuSealPaginationSchema,
|
|
165
|
+
});
|
|
64
166
|
export const DocuSealSignatureRequest = Resource("SignatureKit.DocuSealSignatureRequest", { defaultRemovalPolicy: "retain" });
|
|
65
167
|
export class DocuSealCredentials extends Context.Service()("@signature-kit/docuseal/Credentials") {
|
|
66
168
|
}
|
|
@@ -69,7 +171,7 @@ export const docuSealCredentialsLayer = (options) => Layer.effect(DocuSealCreden
|
|
|
69
171
|
retryable: false,
|
|
70
172
|
provider: PROVIDER,
|
|
71
173
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
72
|
-
schemaName:
|
|
174
|
+
schemaName: DocuSealSchemaName.providerOptions,
|
|
73
175
|
issueMessage: String(issue),
|
|
74
176
|
}))));
|
|
75
177
|
const docuSealBaseUrl = (options) => options.baseUrl === undefined ? DEFAULT_BASE_URL : normalizedBaseUrl(options.baseUrl);
|
|
@@ -77,27 +179,44 @@ const authHeaders = (options) => ({
|
|
|
77
179
|
"X-Auth-Token": Redacted.value(options.apiKey),
|
|
78
180
|
});
|
|
79
181
|
const normalizeSubmissionId = (submissionId) => typeof submissionId === "string" ? submissionId : submissionId.toString();
|
|
80
|
-
const
|
|
182
|
+
const docuSealSubmissionUrl = (baseUrl, submissionId) => `${baseUrl}/submissions/${encodeURIComponent(submissionId)}`;
|
|
183
|
+
const docuSealSubmissionListUrl = (baseUrl, after) => {
|
|
184
|
+
const url = new URL(`${baseUrl}/submissions`);
|
|
185
|
+
url.searchParams.set("limit", "100");
|
|
186
|
+
if (after !== undefined)
|
|
187
|
+
url.searchParams.set("after", after.toString());
|
|
188
|
+
return url.toString();
|
|
189
|
+
};
|
|
190
|
+
const docuSealSubmissionsNextUrl = (baseUrl, pagination) => pagination.next === null
|
|
191
|
+
? Option.none()
|
|
192
|
+
: Option.some(docuSealSubmissionListUrl(baseUrl, pagination.next));
|
|
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) => {
|
|
81
205
|
if (status === undefined)
|
|
82
206
|
return "sent";
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case "canceled":
|
|
97
|
-
return "cancelled";
|
|
98
|
-
default:
|
|
99
|
-
return "sent";
|
|
100
|
-
}
|
|
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"));
|
|
211
|
+
};
|
|
212
|
+
const resolveSubmitterRoles = (recipients) => {
|
|
213
|
+
const roleCounts = new Map();
|
|
214
|
+
return recipients.map((recipient) => {
|
|
215
|
+
const role = recipient.role ?? recipient.name;
|
|
216
|
+
const count = roleCounts.get(role) ?? 0;
|
|
217
|
+
roleCounts.set(role, count + 1);
|
|
218
|
+
return count === 0 ? role : `${role} (${count + 1})`;
|
|
219
|
+
});
|
|
101
220
|
};
|
|
102
221
|
const pickSigningUrl = (submission) => submission.submitters?.[0]?.embed_src ??
|
|
103
222
|
submission.submitters?.[0]?.signing_url ??
|
|
@@ -106,18 +225,21 @@ const pickSigningUrl = (submission) => submission.submitters?.[0]?.embed_src ??
|
|
|
106
225
|
const pickDownloadUrl = (submission) => submission.combined_document_url ??
|
|
107
226
|
submission.documents?.[0]?.url ??
|
|
108
227
|
submission.documents?.[0]?.download_url;
|
|
109
|
-
const
|
|
228
|
+
const toDocuSealSubmissionAttributes = (baseUrl, submission) => {
|
|
110
229
|
const id = normalizeSubmissionId(submission.id);
|
|
111
230
|
const signingUrl = pickSigningUrl(submission);
|
|
112
|
-
const
|
|
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
|
+
const downloadUrl = state === "completed" ? pickDownloadUrl(submission) : undefined;
|
|
113
235
|
return {
|
|
114
236
|
provider: PROVIDER,
|
|
115
237
|
id,
|
|
116
|
-
state
|
|
117
|
-
detailsUrl:
|
|
238
|
+
state,
|
|
239
|
+
detailsUrl: docuSealSubmissionUrl(baseUrl, id),
|
|
118
240
|
...(submission.status === undefined ? {} : { providerStatus: submission.status }),
|
|
119
|
-
...(signingUrl === undefined ? {} : { signingUrl }),
|
|
120
|
-
...(downloadUrl === undefined ? {} : { downloadUrl }),
|
|
241
|
+
...(signingUrl === undefined || signingUrl === null ? {} : { signingUrl }),
|
|
242
|
+
...(downloadUrl === undefined || downloadUrl === null ? {} : { downloadUrl }),
|
|
121
243
|
};
|
|
122
244
|
};
|
|
123
245
|
const requestBytesFromUrl = (http, url) => http.requestBytes({
|
|
@@ -125,105 +247,118 @@ const requestBytesFromUrl = (http, url) => http.requestBytes({
|
|
|
125
247
|
method: "GET",
|
|
126
248
|
url,
|
|
127
249
|
});
|
|
128
|
-
const createSubmission = (http, options, baseUrl, input) =>
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
250
|
+
const createSubmission = (http, options, baseUrl, input) => {
|
|
251
|
+
const submitterRoles = resolveSubmitterRoles(input.recipients);
|
|
252
|
+
return http
|
|
253
|
+
.requestJson({
|
|
254
|
+
provider: PROVIDER,
|
|
255
|
+
method: "POST",
|
|
256
|
+
url: `${baseUrl}/submissions/pdf`,
|
|
257
|
+
headers: {
|
|
258
|
+
"Content-Type": "application/json",
|
|
259
|
+
...authHeaders(options),
|
|
260
|
+
},
|
|
261
|
+
body: JSON.stringify({
|
|
262
|
+
name: input.title,
|
|
263
|
+
send_email: input.send !== false,
|
|
264
|
+
order: options.submittersOrder ?? "preserved",
|
|
265
|
+
documents: input.documents.map((document, index) => ({
|
|
266
|
+
name: document.fileName,
|
|
267
|
+
file: bytesToBase64(document.content),
|
|
268
|
+
position: index,
|
|
269
|
+
})),
|
|
270
|
+
// DocuSeal accepts completed_redirect_url as both a submission default and a submitter override.
|
|
271
|
+
submitters: input.recipients.map((recipient, index) => ({
|
|
272
|
+
name: recipient.name,
|
|
273
|
+
email: recipient.email,
|
|
274
|
+
role: submitterRoles[index],
|
|
275
|
+
order: recipient.routingOrder ?? index,
|
|
276
|
+
...(input.redirectUrl === undefined
|
|
277
|
+
? {}
|
|
278
|
+
: { completed_redirect_url: input.redirectUrl }),
|
|
279
|
+
})),
|
|
280
|
+
...(options.sendSms === undefined ? {} : { send_sms: options.sendSms }),
|
|
281
|
+
...(input.redirectUrl === undefined ? {} : { completed_redirect_url: input.redirectUrl }),
|
|
282
|
+
...(input.expiresAt === undefined ? {} : { expire_at: input.expiresAt.toISOString() }),
|
|
283
|
+
...(input.subject === undefined ? {} : { subject: input.subject }),
|
|
284
|
+
...(input.message === undefined ? {} : { message: { body: input.message } }),
|
|
285
|
+
}),
|
|
286
|
+
}, DocuSealCreateSubmissionResultSchema, DocuSealSchemaName.submissionResult)
|
|
287
|
+
.pipe(Effect.map((result) => {
|
|
288
|
+
if ("id" in result) {
|
|
289
|
+
const mapped = toDocuSealSubmissionAttributes(baseUrl, result);
|
|
290
|
+
const providerStatus = result.status ?? result.submitters?.[0]?.status;
|
|
291
|
+
return {
|
|
292
|
+
...mapped,
|
|
293
|
+
state: input.send === false ? "draft" : "sent",
|
|
294
|
+
...(providerStatus === undefined ? {} : { providerStatus }),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const submitter = result[0];
|
|
298
|
+
const id = normalizeSubmissionId(submitter.submission_id);
|
|
299
|
+
const signingUrl = submitter.embed_src ?? submitter.signing_url ?? submitter.sign_url ?? submitter.url;
|
|
166
300
|
return {
|
|
167
|
-
|
|
301
|
+
provider: PROVIDER,
|
|
302
|
+
id,
|
|
168
303
|
state: input.send === false ? "draft" : "sent",
|
|
169
|
-
|
|
304
|
+
detailsUrl: docuSealSubmissionUrl(baseUrl, id),
|
|
305
|
+
...(submitter.status === undefined ? {} : { providerStatus: submitter.status }),
|
|
306
|
+
...(signingUrl === undefined || signingUrl === null ? {} : { signingUrl }),
|
|
170
307
|
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
provider: PROVIDER,
|
|
177
|
-
id,
|
|
178
|
-
state: input.send === false ? "draft" : "sent",
|
|
179
|
-
detailsUrl: `${baseUrl}/submissions/${id}`,
|
|
180
|
-
...(submitter.status === undefined ? {} : { providerStatus: submitter.status }),
|
|
181
|
-
...(signingUrl === undefined ? {} : { signingUrl }),
|
|
182
|
-
};
|
|
183
|
-
}));
|
|
184
|
-
const fetchSubmission = (http, options, baseUrl, id) => http.requestJson({
|
|
308
|
+
}));
|
|
309
|
+
};
|
|
310
|
+
const listSubmissions = (http, options, baseUrl) => Stream.paginate(docuSealSubmissionListUrl(baseUrl), (url) => http
|
|
311
|
+
.requestJson({
|
|
185
312
|
provider: PROVIDER,
|
|
186
313
|
method: "GET",
|
|
187
|
-
url
|
|
314
|
+
url,
|
|
188
315
|
headers: authHeaders(options),
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
.
|
|
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);
|
|
321
|
+
const fetchSubmission = (http, options, baseUrl, id) => http.requestJson({
|
|
192
322
|
provider: PROVIDER,
|
|
193
323
|
method: "GET",
|
|
194
|
-
url:
|
|
324
|
+
url: docuSealSubmissionUrl(baseUrl, id),
|
|
195
325
|
headers: authHeaders(options),
|
|
196
|
-
},
|
|
197
|
-
.pipe(Effect.map((result) => {
|
|
198
|
-
const submissions = Array.isArray(result) ? result : "data" in result ? result.data : [];
|
|
199
|
-
return submissions.map((submission) => toRemoteSignatureRequest(baseUrl, submission));
|
|
200
|
-
}));
|
|
326
|
+
}, DocuSealSubmissionResultSchema, DocuSealSchemaName.submissionResult);
|
|
201
327
|
const deleteSubmission = (http, options, baseUrl, id) => http
|
|
202
328
|
.requestVoid({
|
|
203
329
|
provider: PROVIDER,
|
|
204
330
|
method: "DELETE",
|
|
205
|
-
url:
|
|
331
|
+
url: docuSealSubmissionUrl(baseUrl, id),
|
|
206
332
|
headers: authHeaders(options),
|
|
207
333
|
})
|
|
208
334
|
.pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.void));
|
|
209
335
|
const fetchSubmissionDocuments = (http, options, baseUrl, id) => http.requestJson({
|
|
210
336
|
provider: PROVIDER,
|
|
211
337
|
method: "GET",
|
|
212
|
-
url: `${baseUrl
|
|
338
|
+
url: `${docuSealSubmissionUrl(baseUrl, id)}/documents?merge=true`,
|
|
213
339
|
headers: authHeaders(options),
|
|
214
|
-
}, DocuSealSubmissionDocumentsResultSchema,
|
|
340
|
+
}, DocuSealSubmissionDocumentsResultSchema, DocuSealSchemaName.submissionDocumentsResult);
|
|
215
341
|
const downloadDocumentFromSubmission = (http, options, baseUrl, id) => fetchSubmission(http, options, baseUrl, id).pipe(Effect.flatMap((submission) => {
|
|
342
|
+
if (docuSealSubmissionState(submission.status) !== "completed") {
|
|
343
|
+
return Effect.fail(new SignatureKitError({
|
|
344
|
+
code: SignatureKitErrorCodeValue.unsupportedOperation,
|
|
345
|
+
retryable: false,
|
|
346
|
+
provider: PROVIDER,
|
|
347
|
+
operation: DocuSealOperation.download,
|
|
348
|
+
reason: `DocuSeal submission ${id} is not completed yet (status: ${submission.status ?? "unknown"}); the signed document does not exist.`,
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
216
351
|
const downloadUrl = pickDownloadUrl(submission);
|
|
217
|
-
if (downloadUrl !== undefined)
|
|
352
|
+
if (downloadUrl !== undefined && downloadUrl !== null)
|
|
218
353
|
return requestBytesFromUrl(http, downloadUrl);
|
|
219
354
|
return fetchSubmissionDocuments(http, options, baseUrl, id).pipe(Effect.flatMap((result) => {
|
|
220
355
|
const url = result.documents[0]?.url ?? result.documents[0]?.download_url;
|
|
221
|
-
if (url === undefined) {
|
|
356
|
+
if (url === undefined || url === null) {
|
|
222
357
|
return Effect.fail(new SignatureKitError({
|
|
223
358
|
code: SignatureKitErrorCodeValue.responseShape,
|
|
224
359
|
retryable: false,
|
|
225
360
|
provider: PROVIDER,
|
|
226
|
-
operation:
|
|
361
|
+
operation: DocuSealOperation.download,
|
|
227
362
|
reason: `DocuSeal submission ${id} has no downloadable document URL.`,
|
|
228
363
|
}));
|
|
229
364
|
}
|
|
@@ -235,15 +370,18 @@ export const DocuSealSignatureRequestProvider = () => Provider.effect(DocuSealSi
|
|
|
235
370
|
const http = yield* SignatureHttpClient;
|
|
236
371
|
const baseUrl = docuSealBaseUrl(options);
|
|
237
372
|
return DocuSealSignatureRequest.Provider.of({
|
|
238
|
-
|
|
239
|
-
|
|
373
|
+
nuke: { skip: true },
|
|
374
|
+
diff: docusealSignatureRequestDiff,
|
|
375
|
+
list: () =>
|
|
376
|
+
// Retained resources must not feed account-wide nuke enumeration.
|
|
377
|
+
Effect.succeed([]),
|
|
240
378
|
read: ({ output }) => output === undefined
|
|
241
379
|
? Effect.succeed(undefined)
|
|
242
|
-
: fetchSubmission(http, options, baseUrl, output.id).pipe(Effect.map((result) =>
|
|
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))),
|
|
243
381
|
reconcile: Effect.fn(function* ({ news, output }) {
|
|
244
382
|
if (output !== undefined)
|
|
245
383
|
return output;
|
|
246
|
-
const input = yield*
|
|
384
|
+
const input = yield* docusealSignatureRequestInputFromResourceProps(news);
|
|
247
385
|
return yield* createSubmission(http, options, baseUrl, input);
|
|
248
386
|
}),
|
|
249
387
|
delete: ({ output }) => deleteSubmission(http, options, baseUrl, output.id),
|
|
@@ -258,12 +396,12 @@ export const getDocuSealSignatureRequest = (options, id) => Effect.gen(function*
|
|
|
258
396
|
retryable: false,
|
|
259
397
|
provider: PROVIDER,
|
|
260
398
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
261
|
-
schemaName:
|
|
399
|
+
schemaName: DocuSealSchemaName.providerOptions,
|
|
262
400
|
issueMessage: String(issue),
|
|
263
401
|
})));
|
|
264
402
|
const http = yield* SignatureHttpClient;
|
|
265
403
|
const baseUrl = docuSealBaseUrl(valid);
|
|
266
|
-
return yield* fetchSubmission(http, valid, baseUrl, id).pipe(Effect.map((result) =>
|
|
404
|
+
return yield* fetchSubmission(http, valid, baseUrl, id).pipe(Effect.map((result) => toDocuSealSubmissionAttributes(baseUrl, result)));
|
|
267
405
|
});
|
|
268
406
|
export const listDocuSealSignatureRequests = (options) => Effect.gen(function* () {
|
|
269
407
|
const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
@@ -271,7 +409,7 @@ export const listDocuSealSignatureRequests = (options) => Effect.gen(function* (
|
|
|
271
409
|
retryable: false,
|
|
272
410
|
provider: PROVIDER,
|
|
273
411
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
274
|
-
schemaName:
|
|
412
|
+
schemaName: DocuSealSchemaName.providerOptions,
|
|
275
413
|
issueMessage: String(issue),
|
|
276
414
|
})));
|
|
277
415
|
const http = yield* SignatureHttpClient;
|
|
@@ -283,7 +421,7 @@ export const deleteDocuSealSignatureRequest = (options, id) => Effect.gen(functi
|
|
|
283
421
|
retryable: false,
|
|
284
422
|
provider: PROVIDER,
|
|
285
423
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
286
|
-
schemaName:
|
|
424
|
+
schemaName: DocuSealSchemaName.providerOptions,
|
|
287
425
|
issueMessage: String(issue),
|
|
288
426
|
})));
|
|
289
427
|
const http = yield* SignatureHttpClient;
|
|
@@ -295,7 +433,7 @@ export const downloadDocuSealSignedDocument = (options, id) => Effect.gen(functi
|
|
|
295
433
|
retryable: false,
|
|
296
434
|
provider: PROVIDER,
|
|
297
435
|
operation: SignatureKitOperationValue.schemaDecode,
|
|
298
|
-
schemaName:
|
|
436
|
+
schemaName: DocuSealSchemaName.providerOptions,
|
|
299
437
|
issueMessage: String(issue),
|
|
300
438
|
})));
|
|
301
439
|
const http = yield* SignatureHttpClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signature-kit/docuseal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
"test": "vitest run"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@signature-kit/
|
|
31
|
-
"@signature-kit/
|
|
30
|
+
"@signature-kit/crypto": "^0.2.1",
|
|
31
|
+
"@signature-kit/http": "^0.1.0",
|
|
32
|
+
"@signature-kit/signatures": "^0.1.0",
|
|
32
33
|
"alchemy": "2.0.0-beta.57",
|
|
33
34
|
"effect": "4.0.0-beta.86"
|
|
34
35
|
},
|