@signature-kit/docuseal 0.1.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 +7 -0
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +303 -0
- package/package.json +53 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Initial npm-ready release for `@signature-kit/docuseal`.
|
|
6
|
+
- Published package metadata, MIT license, README, and package-local changelog.
|
|
7
|
+
- Ships alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and signed-document download.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SignatureKit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @signature-kit/docuseal
|
|
2
|
+
|
|
3
|
+
Alchemy v2 remote-signature provider for DocuSeal submission creation, lookup, deletion, and signed-document download.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @signature-kit/docuseal effect alchemy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
- `@signature-kit/docuseal`
|
|
14
|
+
|
|
15
|
+
## Runtime model
|
|
16
|
+
|
|
17
|
+
SignatureKit packages are Effect-native. Public APIs return typed `Effect.Effect` values; recoverable faults stay in the typed error channel; callers provide required services and layers explicitly at the application boundary.
|
|
18
|
+
|
|
19
|
+
## Version
|
|
20
|
+
|
|
21
|
+
Current npm release line: `0.1.0`.
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT. See `LICENSE`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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";
|
|
4
|
+
import { Resource } from "alchemy";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
7
|
+
declare const DocuSealSubmittersOrderSchema: Schema.Literals<readonly ["preserved", "random"]>;
|
|
8
|
+
export type DocuSealSubmittersOrder = (typeof DocuSealSubmittersOrderSchema)["Type"];
|
|
9
|
+
export declare const DocuSealProviderOptionsSchema: Schema.Struct<{
|
|
10
|
+
readonly apiKey: Schema.ConstraintDecoder<Redacted.Redacted<string>, never>;
|
|
11
|
+
readonly baseUrl: Schema.optional<Schema.NonEmptyString>;
|
|
12
|
+
readonly sendSms: Schema.optional<Schema.Boolean>;
|
|
13
|
+
readonly submittersOrder: Schema.optional<Schema.Literals<readonly ["preserved", "random"]>>;
|
|
14
|
+
}>;
|
|
15
|
+
export type DocuSealProviderOptions = (typeof DocuSealProviderOptionsSchema)["Type"];
|
|
16
|
+
export type DocuSealSignatureRequest = Resource<"SignatureKit.DocuSealSignatureRequest", RemoteSignatureRequestProps, RemoteSignatureRequest>;
|
|
17
|
+
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
|
+
declare const DocuSealProviders_base: Provider.ProviderCollection<DocuSealProviders, "@signature-kit/docuseal/Providers">;
|
|
29
|
+
export declare class DocuSealProviders extends DocuSealProviders_base {
|
|
30
|
+
}
|
|
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>;
|
|
34
|
+
export declare const deleteDocuSealSignatureRequest: (options: DocuSealProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
35
|
+
export declare const downloadDocuSealSignedDocument: (options: DocuSealProviderOptions, id: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAMlB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAEV,sBAAsB,EAEtB,2BAA2B,EAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAqB,MAAM,0BAA0B,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMlE,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;AA4DrF,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAC7C,uCAAuC,EACvC,2BAA2B,EAC3B,sBAAsB,CACvB,CAAC;AAEF,eAAO,MAAM,wBAAwB,2DAGpC,CAAC;;;;;;;AAEF,qBAAa,mBAAoB,SAAQ,wBAGC;CAAG;AAE7C,eAAO,MAAM,wBAAwB,GACnC,SAAS,uBAAuB,KAC/B,KAAK,CAAC,KAAK,CAAC,mBAAmB,EAAE,iBAAiB,CAgBlD,CAAC;AAyPJ,eAAO,MAAM,gCAAgC,kHA6B1C,CAAC;;AACJ,qBAAa,iBAAkB,SAAQ,sBAEtC;CAAG;AAEJ,eAAO,MAAM,SAAS,GAAI,SAAS,uBAAuB,2EAIvD,CAAC;AAEJ,eAAO,MAAM,2BAA2B,GACtC,SAAS,uBAAuB,EAChC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,iBAAiB,EAAE,mBAAmB,CAoB3E,CAAC;AAEL,eAAO,MAAM,6BAA6B,GACxC,SAAS,uBAAuB,KAC/B,MAAM,CAAC,MAAM,CAAC,SAAS,sBAAsB,EAAE,EAAE,iBAAiB,EAAE,mBAAmB,CAiBtF,CAAC;AAEL,eAAO,MAAM,8BAA8B,GACzC,SAAS,uBAAuB,EAChC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,8BAA8B,GACzC,SAAS,uBAAuB,EAChC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAiB/D,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
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";
|
|
4
|
+
import { Resource } from "alchemy";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
7
|
+
const PROVIDER = "docuseal";
|
|
8
|
+
const DOCUSEAL_PROVIDER_COLLECTION_ID = "@signature-kit/docuseal/Providers";
|
|
9
|
+
const DEFAULT_BASE_URL = "https://api.docuseal.com";
|
|
10
|
+
const DocuSealSubmittersOrderSchema = Schema.Literals(["preserved", "random"]);
|
|
11
|
+
export const DocuSealProviderOptionsSchema = Schema.Struct({
|
|
12
|
+
apiKey: redactedStringSchema,
|
|
13
|
+
baseUrl: Schema.optional(Schema.NonEmptyString),
|
|
14
|
+
sendSms: Schema.optional(Schema.Boolean),
|
|
15
|
+
submittersOrder: Schema.optional(DocuSealSubmittersOrderSchema),
|
|
16
|
+
});
|
|
17
|
+
const DocuSealSubmissionIdSchema = Schema.Union([Schema.Number, Schema.NonEmptyString]);
|
|
18
|
+
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),
|
|
23
|
+
};
|
|
24
|
+
const DocuSealCreateSubmitterResultSchema = Schema.Struct({
|
|
25
|
+
submission_id: DocuSealSubmissionIdSchema,
|
|
26
|
+
status: Schema.optional(Schema.String),
|
|
27
|
+
...DocuSealSubmitterLinkFields,
|
|
28
|
+
});
|
|
29
|
+
const DocuSealSubmitterResultSchema = Schema.Struct({
|
|
30
|
+
status: Schema.optional(Schema.String),
|
|
31
|
+
...DocuSealSubmitterLinkFields,
|
|
32
|
+
download_url: Schema.optional(Schema.String),
|
|
33
|
+
});
|
|
34
|
+
const DocuSealSubmissionResultSchema = Schema.Struct({
|
|
35
|
+
id: DocuSealSubmissionIdSchema,
|
|
36
|
+
status: Schema.optional(Schema.String),
|
|
37
|
+
submitters: Schema.optional(Schema.Array(DocuSealSubmitterResultSchema)),
|
|
38
|
+
combined_document_url: Schema.optional(Schema.String),
|
|
39
|
+
documents: Schema.optional(Schema.Array(Schema.Struct({
|
|
40
|
+
id: Schema.optional(DocuSealSubmissionIdSchema),
|
|
41
|
+
name: Schema.optional(Schema.String),
|
|
42
|
+
url: Schema.optional(Schema.String),
|
|
43
|
+
download_url: Schema.optional(Schema.String),
|
|
44
|
+
}))),
|
|
45
|
+
});
|
|
46
|
+
const DocuSealCreateSubmissionResultSchema = Schema.Union([
|
|
47
|
+
Schema.NonEmptyArray(DocuSealCreateSubmitterResultSchema),
|
|
48
|
+
DocuSealSubmissionResultSchema,
|
|
49
|
+
]);
|
|
50
|
+
const DocuSealSubmissionDocumentsResultSchema = Schema.Struct({
|
|
51
|
+
documents: Schema.Array(Schema.Struct({
|
|
52
|
+
url: Schema.optional(Schema.String),
|
|
53
|
+
download_url: Schema.optional(Schema.String),
|
|
54
|
+
})),
|
|
55
|
+
});
|
|
56
|
+
const DocuSealSubmissionsResultSchema = Schema.Union([
|
|
57
|
+
Schema.Array(DocuSealSubmissionResultSchema),
|
|
58
|
+
Schema.Struct({
|
|
59
|
+
data: Schema.Array(DocuSealSubmissionResultSchema),
|
|
60
|
+
pagination: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
61
|
+
}),
|
|
62
|
+
DocuSealSubmissionDocumentsResultSchema,
|
|
63
|
+
]);
|
|
64
|
+
export const DocuSealSignatureRequest = Resource("SignatureKit.DocuSealSignatureRequest", { defaultRemovalPolicy: "retain" });
|
|
65
|
+
export class DocuSealCredentials extends Context.Service()("@signature-kit/docuseal/Credentials") {
|
|
66
|
+
}
|
|
67
|
+
export const docuSealCredentialsLayer = (options) => Layer.effect(DocuSealCredentials, Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
68
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
69
|
+
retryable: false,
|
|
70
|
+
provider: PROVIDER,
|
|
71
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
72
|
+
schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
|
|
73
|
+
issueMessage: String(issue),
|
|
74
|
+
}))));
|
|
75
|
+
const docuSealBaseUrl = (options) => options.baseUrl === undefined ? DEFAULT_BASE_URL : normalizedBaseUrl(options.baseUrl);
|
|
76
|
+
const authHeaders = (options) => ({
|
|
77
|
+
"X-Auth-Token": Redacted.value(options.apiKey),
|
|
78
|
+
});
|
|
79
|
+
const normalizeSubmissionId = (submissionId) => typeof submissionId === "string" ? submissionId : submissionId.toString();
|
|
80
|
+
const mapRemoteState = (status) => {
|
|
81
|
+
if (status === undefined)
|
|
82
|
+
return "sent";
|
|
83
|
+
switch (status.toLowerCase()) {
|
|
84
|
+
case "draft":
|
|
85
|
+
return "draft";
|
|
86
|
+
case "completed":
|
|
87
|
+
return "completed";
|
|
88
|
+
case "declined":
|
|
89
|
+
return "declined";
|
|
90
|
+
case "expired":
|
|
91
|
+
return "expired";
|
|
92
|
+
case "deleted":
|
|
93
|
+
case "archived":
|
|
94
|
+
return "deleted";
|
|
95
|
+
case "cancelled":
|
|
96
|
+
case "canceled":
|
|
97
|
+
return "cancelled";
|
|
98
|
+
default:
|
|
99
|
+
return "sent";
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const pickSigningUrl = (submission) => submission.submitters?.[0]?.embed_src ??
|
|
103
|
+
submission.submitters?.[0]?.signing_url ??
|
|
104
|
+
submission.submitters?.[0]?.sign_url ??
|
|
105
|
+
submission.submitters?.[0]?.url;
|
|
106
|
+
const pickDownloadUrl = (submission) => submission.combined_document_url ??
|
|
107
|
+
submission.documents?.[0]?.url ??
|
|
108
|
+
submission.documents?.[0]?.download_url;
|
|
109
|
+
const toRemoteSignatureRequest = (baseUrl, submission) => {
|
|
110
|
+
const id = normalizeSubmissionId(submission.id);
|
|
111
|
+
const signingUrl = pickSigningUrl(submission);
|
|
112
|
+
const downloadUrl = pickDownloadUrl(submission);
|
|
113
|
+
return {
|
|
114
|
+
provider: PROVIDER,
|
|
115
|
+
id,
|
|
116
|
+
state: mapRemoteState(submission.status),
|
|
117
|
+
detailsUrl: `${baseUrl}/submissions/${id}`,
|
|
118
|
+
...(submission.status === undefined ? {} : { providerStatus: submission.status }),
|
|
119
|
+
...(signingUrl === undefined ? {} : { signingUrl }),
|
|
120
|
+
...(downloadUrl === undefined ? {} : { downloadUrl }),
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const requestBytesFromUrl = (http, url) => http.requestBytes({
|
|
124
|
+
provider: PROVIDER,
|
|
125
|
+
method: "GET",
|
|
126
|
+
url,
|
|
127
|
+
});
|
|
128
|
+
const createSubmission = (http, options, baseUrl, input) => http
|
|
129
|
+
.requestJson({
|
|
130
|
+
provider: PROVIDER,
|
|
131
|
+
method: "POST",
|
|
132
|
+
url: `${baseUrl}/submissions/pdf`,
|
|
133
|
+
headers: {
|
|
134
|
+
"Content-Type": "application/json",
|
|
135
|
+
...authHeaders(options),
|
|
136
|
+
},
|
|
137
|
+
body: JSON.stringify({
|
|
138
|
+
name: input.title,
|
|
139
|
+
send_email: input.send !== false,
|
|
140
|
+
order: options.submittersOrder ?? "preserved",
|
|
141
|
+
documents: input.documents.map((document, index) => ({
|
|
142
|
+
name: document.fileName,
|
|
143
|
+
file: bytesToBase64(document.content),
|
|
144
|
+
position: index,
|
|
145
|
+
})),
|
|
146
|
+
submitters: input.recipients.map((recipient, index) => ({
|
|
147
|
+
name: recipient.name,
|
|
148
|
+
email: recipient.email,
|
|
149
|
+
role: recipient.role ?? recipient.name,
|
|
150
|
+
order: recipient.routingOrder ?? index,
|
|
151
|
+
...(input.redirectUrl === undefined
|
|
152
|
+
? {}
|
|
153
|
+
: { completed_redirect_url: input.redirectUrl }),
|
|
154
|
+
})),
|
|
155
|
+
...(options.sendSms === undefined ? {} : { send_sms: options.sendSms }),
|
|
156
|
+
...(input.redirectUrl === undefined ? {} : { completed_redirect_url: input.redirectUrl }),
|
|
157
|
+
...(input.expiresAt === undefined ? {} : { expire_at: input.expiresAt.toISOString() }),
|
|
158
|
+
...(input.subject === undefined ? {} : { subject: input.subject }),
|
|
159
|
+
...(input.message === undefined ? {} : { message: { body: input.message } }),
|
|
160
|
+
}),
|
|
161
|
+
}, DocuSealCreateSubmissionResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionResult)
|
|
162
|
+
.pipe(Effect.map((result) => {
|
|
163
|
+
if ("id" in result) {
|
|
164
|
+
const mapped = toRemoteSignatureRequest(baseUrl, result);
|
|
165
|
+
const providerStatus = result.status ?? result.submitters?.[0]?.status;
|
|
166
|
+
return {
|
|
167
|
+
...mapped,
|
|
168
|
+
state: input.send === false ? "draft" : "sent",
|
|
169
|
+
...(providerStatus === undefined ? {} : { providerStatus }),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const submitter = result[0];
|
|
173
|
+
const id = normalizeSubmissionId(submitter.submission_id);
|
|
174
|
+
const signingUrl = submitter.embed_src ?? submitter.signing_url ?? submitter.sign_url ?? submitter.url;
|
|
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({
|
|
185
|
+
provider: PROVIDER,
|
|
186
|
+
method: "GET",
|
|
187
|
+
url: `${baseUrl}/submissions/${id}`,
|
|
188
|
+
headers: authHeaders(options),
|
|
189
|
+
}, DocuSealSubmissionResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionResult);
|
|
190
|
+
const listSubmissions = (http, options, baseUrl) => http
|
|
191
|
+
.requestJson({
|
|
192
|
+
provider: PROVIDER,
|
|
193
|
+
method: "GET",
|
|
194
|
+
url: `${baseUrl}/submissions`,
|
|
195
|
+
headers: authHeaders(options),
|
|
196
|
+
}, DocuSealSubmissionsResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionsResult)
|
|
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
|
+
}));
|
|
201
|
+
const deleteSubmission = (http, options, baseUrl, id) => http
|
|
202
|
+
.requestVoid({
|
|
203
|
+
provider: PROVIDER,
|
|
204
|
+
method: "DELETE",
|
|
205
|
+
url: `${baseUrl}/submissions/${id}`,
|
|
206
|
+
headers: authHeaders(options),
|
|
207
|
+
})
|
|
208
|
+
.pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.void));
|
|
209
|
+
const fetchSubmissionDocuments = (http, options, baseUrl, id) => http.requestJson({
|
|
210
|
+
provider: PROVIDER,
|
|
211
|
+
method: "GET",
|
|
212
|
+
url: `${baseUrl}/submissions/${id}/documents?merge=true`,
|
|
213
|
+
headers: authHeaders(options),
|
|
214
|
+
}, DocuSealSubmissionDocumentsResultSchema, SignatureKitSchemaNameValue.docuSealSubmissionDocumentsResult);
|
|
215
|
+
const downloadDocumentFromSubmission = (http, options, baseUrl, id) => fetchSubmission(http, options, baseUrl, id).pipe(Effect.flatMap((submission) => {
|
|
216
|
+
const downloadUrl = pickDownloadUrl(submission);
|
|
217
|
+
if (downloadUrl !== undefined)
|
|
218
|
+
return requestBytesFromUrl(http, downloadUrl);
|
|
219
|
+
return fetchSubmissionDocuments(http, options, baseUrl, id).pipe(Effect.flatMap((result) => {
|
|
220
|
+
const url = result.documents[0]?.url ?? result.documents[0]?.download_url;
|
|
221
|
+
if (url === undefined) {
|
|
222
|
+
return Effect.fail(new SignatureKitError({
|
|
223
|
+
code: SignatureKitErrorCodeValue.responseShape,
|
|
224
|
+
retryable: false,
|
|
225
|
+
provider: PROVIDER,
|
|
226
|
+
operation: SignatureKitOperationValue.remoteDownload,
|
|
227
|
+
reason: `DocuSeal submission ${id} has no downloadable document URL.`,
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
return requestBytesFromUrl(http, url);
|
|
231
|
+
}));
|
|
232
|
+
}));
|
|
233
|
+
export const DocuSealSignatureRequestProvider = () => Provider.effect(DocuSealSignatureRequest, Effect.gen(function* () {
|
|
234
|
+
const options = yield* DocuSealCredentials;
|
|
235
|
+
const http = yield* SignatureHttpClient;
|
|
236
|
+
const baseUrl = docuSealBaseUrl(options);
|
|
237
|
+
return DocuSealSignatureRequest.Provider.of({
|
|
238
|
+
diff: ({ olds }) => Effect.succeed(olds === undefined ? undefined : { action: "noop" }),
|
|
239
|
+
list: () => listSubmissions(http, options, baseUrl),
|
|
240
|
+
read: ({ output }) => output === undefined
|
|
241
|
+
? Effect.succeed(undefined)
|
|
242
|
+
: 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))),
|
|
243
|
+
reconcile: Effect.fn(function* ({ news, output }) {
|
|
244
|
+
if (output !== undefined)
|
|
245
|
+
return output;
|
|
246
|
+
const input = yield* remoteSignatureInputFromResourceProps(PROVIDER, news);
|
|
247
|
+
return yield* createSubmission(http, options, baseUrl, input);
|
|
248
|
+
}),
|
|
249
|
+
delete: ({ output }) => deleteSubmission(http, options, baseUrl, output.id),
|
|
250
|
+
});
|
|
251
|
+
}));
|
|
252
|
+
export class DocuSealProviders extends Provider.ProviderCollection()(DOCUSEAL_PROVIDER_COLLECTION_ID) {
|
|
253
|
+
}
|
|
254
|
+
export const providers = (options) => Layer.effect(DocuSealProviders, Provider.collection([DocuSealSignatureRequest])).pipe(Layer.provide(DocuSealSignatureRequestProvider()), Layer.provide(docuSealCredentialsLayer(options)));
|
|
255
|
+
export const getDocuSealSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
256
|
+
const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
257
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
258
|
+
retryable: false,
|
|
259
|
+
provider: PROVIDER,
|
|
260
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
261
|
+
schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
|
|
262
|
+
issueMessage: String(issue),
|
|
263
|
+
})));
|
|
264
|
+
const http = yield* SignatureHttpClient;
|
|
265
|
+
const baseUrl = docuSealBaseUrl(valid);
|
|
266
|
+
return yield* fetchSubmission(http, valid, baseUrl, id).pipe(Effect.map((result) => toRemoteSignatureRequest(baseUrl, result)));
|
|
267
|
+
});
|
|
268
|
+
export const listDocuSealSignatureRequests = (options) => Effect.gen(function* () {
|
|
269
|
+
const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
270
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
271
|
+
retryable: false,
|
|
272
|
+
provider: PROVIDER,
|
|
273
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
274
|
+
schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
|
|
275
|
+
issueMessage: String(issue),
|
|
276
|
+
})));
|
|
277
|
+
const http = yield* SignatureHttpClient;
|
|
278
|
+
return yield* listSubmissions(http, valid, docuSealBaseUrl(valid));
|
|
279
|
+
});
|
|
280
|
+
export const deleteDocuSealSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
281
|
+
const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
282
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
283
|
+
retryable: false,
|
|
284
|
+
provider: PROVIDER,
|
|
285
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
286
|
+
schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
|
|
287
|
+
issueMessage: String(issue),
|
|
288
|
+
})));
|
|
289
|
+
const http = yield* SignatureHttpClient;
|
|
290
|
+
return yield* deleteSubmission(http, valid, docuSealBaseUrl(valid), id);
|
|
291
|
+
});
|
|
292
|
+
export const downloadDocuSealSignedDocument = (options, id) => Effect.gen(function* () {
|
|
293
|
+
const valid = yield* Schema.decodeUnknownEffect(DocuSealProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
294
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
295
|
+
retryable: false,
|
|
296
|
+
provider: PROVIDER,
|
|
297
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
298
|
+
schemaName: SignatureKitSchemaNameValue.docuSealProviderOptions,
|
|
299
|
+
issueMessage: String(issue),
|
|
300
|
+
})));
|
|
301
|
+
const http = yield* SignatureHttpClient;
|
|
302
|
+
return yield* downloadDocumentFromSubmission(http, valid, docuSealBaseUrl(valid), id);
|
|
303
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signature-kit/docuseal",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"CHANGELOG.md"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -b tsconfig.json",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"test": "vitest run"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@signature-kit/core": "^0.1.0",
|
|
31
|
+
"@signature-kit/crypto": "^0.1.0",
|
|
32
|
+
"alchemy": "2.0.0-beta.57",
|
|
33
|
+
"effect": "4.0.0-beta.86"
|
|
34
|
+
},
|
|
35
|
+
"nx": {
|
|
36
|
+
"targets": {
|
|
37
|
+
"npm-pack": {
|
|
38
|
+
"executor": "nx:run-commands",
|
|
39
|
+
"options": {
|
|
40
|
+
"command": "npm pack --dry-run --json",
|
|
41
|
+
"cwd": "{projectRoot}"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"npm-publish": {
|
|
45
|
+
"executor": "nx:run-commands",
|
|
46
|
+
"options": {
|
|
47
|
+
"command": "npm publish --access public",
|
|
48
|
+
"cwd": "{projectRoot}"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|