@signature-kit/documenso 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 +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +312 -0
- package/package.json +52 -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/documenso`.
|
|
6
|
+
- Published package metadata, MIT license, README, and package-local changelog.
|
|
7
|
+
- Ships alchemy v2 remote-signature provider for Documenso envelope 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/documenso
|
|
2
|
+
|
|
3
|
+
Alchemy v2 remote-signature provider for Documenso envelope creation, lookup, deletion, and signed-document download.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @signature-kit/documenso effect alchemy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
- `@signature-kit/documenso`
|
|
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,36 @@
|
|
|
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 DocumensoAuthorizationSchemeSchema: Schema.Literals<readonly ["raw", "bearer"]>;
|
|
8
|
+
export type DocumensoAuthorizationScheme = (typeof DocumensoAuthorizationSchemeSchema)["Type"];
|
|
9
|
+
export declare const DocumensoProviderOptionsSchema: Schema.Struct<{
|
|
10
|
+
readonly apiKey: Schema.ConstraintDecoder<Redacted.Redacted<string>, never>;
|
|
11
|
+
readonly baseUrl: Schema.optional<Schema.NonEmptyString>;
|
|
12
|
+
readonly authorizationScheme: Schema.optional<Schema.Literals<readonly ["raw", "bearer"]>>;
|
|
13
|
+
}>;
|
|
14
|
+
export type DocumensoProviderOptions = (typeof DocumensoProviderOptionsSchema)["Type"];
|
|
15
|
+
export type DocumensoSignatureRequest = Resource<"SignatureKit.DocumensoSignatureRequest", RemoteSignatureRequestProps, RemoteSignatureRequest>;
|
|
16
|
+
export declare const DocumensoSignatureRequest: import("alchemy").ResourceClass<DocumensoSignatureRequest>;
|
|
17
|
+
declare const DocumensoCredentials_base: Context.ServiceClass<DocumensoCredentials, "@signature-kit/documenso/Credentials", {
|
|
18
|
+
readonly apiKey: Redacted.Redacted<string>;
|
|
19
|
+
readonly baseUrl?: string | undefined;
|
|
20
|
+
readonly authorizationScheme?: "raw" | "bearer" | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare class DocumensoCredentials extends DocumensoCredentials_base {
|
|
23
|
+
}
|
|
24
|
+
export declare const documensoCredentialsLayer: (options: DocumensoProviderOptions) => Layer.Layer<DocumensoCredentials, SignatureKitError>;
|
|
25
|
+
export declare const DocumensoSignatureRequestProvider: () => Layer.Layer<Provider.Provider<DocumensoSignatureRequest>, never, DocumensoCredentials | SignatureHttpClient>;
|
|
26
|
+
declare const DocumensoProviders_base: Provider.ProviderCollection<DocumensoProviders, "@signature-kit/documenso/Providers">;
|
|
27
|
+
export declare class DocumensoProviders extends DocumensoProviders_base {
|
|
28
|
+
}
|
|
29
|
+
export declare const providers: (options: DocumensoProviderOptions) => Layer.Layer<DocumensoProviders, SignatureKitError, SignatureHttpClient>;
|
|
30
|
+
export declare const getDocumensoSignatureRequest: (options: DocumensoProviderOptions, id: string) => Effect.Effect<RemoteSignatureRequest, SignatureKitError, SignatureHttpClient>;
|
|
31
|
+
export declare const listDocumensoSignatureRequests: (options: DocumensoProviderOptions) => Effect.Effect<ReadonlyArray<RemoteSignatureRequest>, SignatureKitError, SignatureHttpClient>;
|
|
32
|
+
export declare const cancelDocumensoSignatureRequest: (options: DocumensoProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
33
|
+
export declare const deleteDocumensoSignatureRequest: (options: DocumensoProviderOptions, id: string) => Effect.Effect<void, SignatureKitError, SignatureHttpClient>;
|
|
34
|
+
export declare const downloadDocumensoSignedDocument: (options: DocumensoProviderOptions, envelopeId: string) => Effect.Effect<Uint8Array, SignatureKitError, SignatureHttpClient>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,kCAAkC,6CAAqC,CAAC;AAC9E,MAAM,MAAM,4BAA4B,GAAG,CAAC,OAAO,kCAAkC,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/F,eAAO,MAAM,8BAA8B;;;;EAIzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC;AA8CvF,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAC9C,wCAAwC,EACxC,2BAA2B,EAC3B,sBAAsB,CACvB,CAAC;AAEF,eAAO,MAAM,yBAAyB,4DAGrC,CAAC;;;;;;AACF,qBAAa,oBAAqB,SAAQ,yBAGC;CAAG;AAE9C,eAAO,MAAM,yBAAyB,GACpC,SAAS,wBAAwB,KAChC,KAAK,CAAC,KAAK,CAAC,oBAAoB,EAAE,iBAAiB,CAgBnD,CAAC;AAoSJ,eAAO,MAAM,iCAAiC,oHA4B3C,CAAC;;AAEJ,qBAAa,kBAAmB,SAAQ,uBAEvC;CAAG;AAEJ,eAAO,MAAM,SAAS,GAAI,SAAS,wBAAwB,4EAIxD,CAAC;AAEJ,eAAO,MAAM,4BAA4B,GACvC,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,iBAAiB,EAAE,mBAAmB,CAiB3E,CAAC;AAEL,eAAO,MAAM,8BAA8B,GACzC,SAAS,wBAAwB,KAChC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC,EAAE,iBAAiB,EAAE,mBAAmB,CAiB1F,CAAC;AAEL,eAAO,MAAM,+BAA+B,GAC1C,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,+BAA+B,GAC1C,SAAS,wBAAwB,EACjC,IAAI,MAAM,KACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,CAiBzD,CAAC;AAEL,eAAO,MAAM,+BAA+B,GAC1C,SAAS,wBAAwB,EACjC,YAAY,MAAM,KACjB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,CAiB/D,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { SignatureKitError, SignatureKitErrorCodeValue, SignatureKitOperationValue, SignatureKitSchemaNameValue, redactedStringSchema, remoteSignatureInputFromResourceProps, } from "@signature-kit/core/config";
|
|
2
|
+
import { SignatureHttpClient, normalizedBaseUrl } from "@signature-kit/core/http";
|
|
3
|
+
import { Resource } from "alchemy";
|
|
4
|
+
import * as Provider from "alchemy/Provider";
|
|
5
|
+
import { Context, Effect, Layer, Redacted, Schema } from "effect";
|
|
6
|
+
const PROVIDER = "documenso";
|
|
7
|
+
const DOCUMENSO_PROVIDER_COLLECTION_ID = "@signature-kit/documenso/Providers";
|
|
8
|
+
const DEFAULT_BASE_URL = "https://app.documenso.com/api/v2";
|
|
9
|
+
const DocumensoAuthorizationSchemeSchema = Schema.Literals(["raw", "bearer"]);
|
|
10
|
+
export const DocumensoProviderOptionsSchema = Schema.Struct({
|
|
11
|
+
apiKey: redactedStringSchema,
|
|
12
|
+
baseUrl: Schema.optional(Schema.NonEmptyString),
|
|
13
|
+
authorizationScheme: Schema.optional(DocumensoAuthorizationSchemeSchema),
|
|
14
|
+
});
|
|
15
|
+
const DocumensoCreateEnvelopeResultSchema = Schema.Struct({
|
|
16
|
+
id: Schema.NonEmptyString,
|
|
17
|
+
});
|
|
18
|
+
const DocumensoRecipientResultSchema = Schema.Struct({
|
|
19
|
+
id: Schema.Number,
|
|
20
|
+
name: Schema.String,
|
|
21
|
+
email: Schema.String,
|
|
22
|
+
role: Schema.String,
|
|
23
|
+
signingOrder: Schema.optional(Schema.NullOr(Schema.Number)),
|
|
24
|
+
signingUrl: Schema.String,
|
|
25
|
+
});
|
|
26
|
+
const DocumensoDistributeEnvelopeResultSchema = Schema.Struct({
|
|
27
|
+
success: Schema.Boolean,
|
|
28
|
+
id: Schema.NonEmptyString,
|
|
29
|
+
recipients: Schema.Array(DocumensoRecipientResultSchema),
|
|
30
|
+
});
|
|
31
|
+
const DocumensoEnvelopeRecipientResultSchema = Schema.Struct({
|
|
32
|
+
id: Schema.Union([Schema.NonEmptyString, Schema.Number]),
|
|
33
|
+
name: Schema.String,
|
|
34
|
+
email: Schema.String,
|
|
35
|
+
role: Schema.String,
|
|
36
|
+
signingUrl: Schema.optional(Schema.NonEmptyString),
|
|
37
|
+
});
|
|
38
|
+
const DocumensoEnvelopeItemResultSchema = Schema.Struct({
|
|
39
|
+
id: Schema.NonEmptyString,
|
|
40
|
+
});
|
|
41
|
+
const DocumensoEnvelopeResultSchema = Schema.Struct({
|
|
42
|
+
id: Schema.NonEmptyString,
|
|
43
|
+
status: Schema.NonEmptyString,
|
|
44
|
+
recipients: Schema.optional(Schema.Array(DocumensoEnvelopeRecipientResultSchema)),
|
|
45
|
+
envelopeItems: Schema.optional(Schema.Array(DocumensoEnvelopeItemResultSchema)),
|
|
46
|
+
});
|
|
47
|
+
const DocumensoEnvelopeListResultSchema = Schema.Struct({
|
|
48
|
+
data: Schema.Array(DocumensoEnvelopeResultSchema),
|
|
49
|
+
pagination: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
50
|
+
});
|
|
51
|
+
export const DocumensoSignatureRequest = Resource("SignatureKit.DocumensoSignatureRequest", { defaultRemovalPolicy: "retain" });
|
|
52
|
+
export class DocumensoCredentials extends Context.Service()("@signature-kit/documenso/Credentials") {
|
|
53
|
+
}
|
|
54
|
+
export const documensoCredentialsLayer = (options) => Layer.effect(DocumensoCredentials, Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
55
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
56
|
+
retryable: false,
|
|
57
|
+
provider: PROVIDER,
|
|
58
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
59
|
+
schemaName: SignatureKitSchemaNameValue.documensoProviderOptions,
|
|
60
|
+
issueMessage: String(issue),
|
|
61
|
+
}))));
|
|
62
|
+
const documensoBaseUrl = (options) => options.baseUrl === undefined ? DEFAULT_BASE_URL : normalizedBaseUrl(options.baseUrl);
|
|
63
|
+
const documensoAuthorization = (options) => {
|
|
64
|
+
const token = Redacted.value(options.apiKey);
|
|
65
|
+
return options.authorizationScheme === "bearer" ? `Bearer ${token}` : token;
|
|
66
|
+
};
|
|
67
|
+
const requestMeta = (input) => ({
|
|
68
|
+
...(input.subject === undefined ? {} : { subject: input.subject }),
|
|
69
|
+
...(input.message === undefined ? {} : { message: input.message }),
|
|
70
|
+
...(input.redirectUrl === undefined ? {} : { redirectUrl: input.redirectUrl }),
|
|
71
|
+
});
|
|
72
|
+
const createEnvelopeBody = (input) => {
|
|
73
|
+
const formData = new FormData();
|
|
74
|
+
formData.append("payload", JSON.stringify({
|
|
75
|
+
type: "DOCUMENT",
|
|
76
|
+
title: input.title,
|
|
77
|
+
recipients: input.recipients.map((recipient) => ({
|
|
78
|
+
name: recipient.name,
|
|
79
|
+
email: recipient.email,
|
|
80
|
+
role: recipient.role === "approver" ? "APPROVER" : "SIGNER",
|
|
81
|
+
...(recipient.routingOrder === undefined ? {} : { signingOrder: recipient.routingOrder }),
|
|
82
|
+
})),
|
|
83
|
+
meta: requestMeta(input),
|
|
84
|
+
}));
|
|
85
|
+
input.documents.forEach((document) => formData.append("files", new Blob([Uint8Array.from(document.content)], { type: document.mimeType }), document.fileName));
|
|
86
|
+
return formData;
|
|
87
|
+
};
|
|
88
|
+
const createEnvelope = (http, options, baseUrl, input) => http.requestJson({
|
|
89
|
+
provider: PROVIDER,
|
|
90
|
+
method: "POST",
|
|
91
|
+
url: `${baseUrl}/envelope/create`,
|
|
92
|
+
headers: { Authorization: documensoAuthorization(options) },
|
|
93
|
+
body: createEnvelopeBody(input),
|
|
94
|
+
}, DocumensoCreateEnvelopeResultSchema, SignatureKitSchemaNameValue.documensoCreateEnvelopeResult);
|
|
95
|
+
const distributeEnvelope = (http, options, baseUrl, input, envelope) => http
|
|
96
|
+
.requestJson({
|
|
97
|
+
provider: PROVIDER,
|
|
98
|
+
method: "POST",
|
|
99
|
+
url: `${baseUrl}/envelope/distribute`,
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
Authorization: documensoAuthorization(options),
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify({ envelopeId: envelope.id, meta: requestMeta(input) }),
|
|
105
|
+
}, DocumensoDistributeEnvelopeResultSchema, SignatureKitSchemaNameValue.documensoDistributeEnvelopeResult)
|
|
106
|
+
.pipe(Effect.map((result) => ({
|
|
107
|
+
provider: PROVIDER,
|
|
108
|
+
id: result.id,
|
|
109
|
+
state: "sent",
|
|
110
|
+
providerStatus: result.success ? "distributed" : "not_distributed",
|
|
111
|
+
detailsUrl: `${baseUrl}/envelope/${result.id}`,
|
|
112
|
+
...(result.recipients[0]?.signingUrl === undefined
|
|
113
|
+
? {}
|
|
114
|
+
: { signingUrl: result.recipients[0].signingUrl }),
|
|
115
|
+
})));
|
|
116
|
+
const mapEnvelopeStatus = (status) => {
|
|
117
|
+
switch (status.toUpperCase()) {
|
|
118
|
+
case "DRAFT":
|
|
119
|
+
return "draft";
|
|
120
|
+
case "PENDING":
|
|
121
|
+
case "PROCESSING":
|
|
122
|
+
case "SENT":
|
|
123
|
+
return "sent";
|
|
124
|
+
case "COMPLETED":
|
|
125
|
+
return "completed";
|
|
126
|
+
case "REJECTED":
|
|
127
|
+
case "DECLINED":
|
|
128
|
+
return "declined";
|
|
129
|
+
case "CANCELED":
|
|
130
|
+
case "CANCELLED":
|
|
131
|
+
return "cancelled";
|
|
132
|
+
case "DELETED":
|
|
133
|
+
return "deleted";
|
|
134
|
+
case "EXPIRED":
|
|
135
|
+
return "expired";
|
|
136
|
+
default:
|
|
137
|
+
return "sent";
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const envelopeSignedDownloadUrl = (baseUrl, envelopeItemId) => {
|
|
141
|
+
const url = new URL(`${baseUrl}/envelope/item/${envelopeItemId}/download`);
|
|
142
|
+
url.searchParams.set("version", "signed");
|
|
143
|
+
return url.toString();
|
|
144
|
+
};
|
|
145
|
+
const envelopeSignedDownloadUrlFromEnvelope = (baseUrl, envelope) => {
|
|
146
|
+
const envelopeItemId = envelope.envelopeItems?.[0]?.id;
|
|
147
|
+
return envelopeItemId === undefined
|
|
148
|
+
? undefined
|
|
149
|
+
: envelopeSignedDownloadUrl(baseUrl, envelopeItemId);
|
|
150
|
+
};
|
|
151
|
+
const mapEnvelopeToRemoteRequest = (baseUrl, envelope) => {
|
|
152
|
+
const signingUrl = envelope.recipients?.[0]?.signingUrl;
|
|
153
|
+
const downloadUrl = envelopeSignedDownloadUrlFromEnvelope(baseUrl, envelope);
|
|
154
|
+
return {
|
|
155
|
+
provider: PROVIDER,
|
|
156
|
+
id: envelope.id,
|
|
157
|
+
state: mapEnvelopeStatus(envelope.status),
|
|
158
|
+
providerStatus: envelope.status,
|
|
159
|
+
detailsUrl: `${baseUrl}/envelope/${envelope.id}`,
|
|
160
|
+
...(signingUrl === undefined ? {} : { signingUrl }),
|
|
161
|
+
...(downloadUrl === undefined ? {} : { downloadUrl }),
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const getEnvelope = (http, options, baseUrl, id) => http
|
|
165
|
+
.requestJson({
|
|
166
|
+
provider: PROVIDER,
|
|
167
|
+
method: "GET",
|
|
168
|
+
url: `${baseUrl}/envelope/${id}`,
|
|
169
|
+
headers: { Authorization: documensoAuthorization(options) },
|
|
170
|
+
}, DocumensoEnvelopeResultSchema, SignatureKitSchemaNameValue.documensoEnvelopeResult)
|
|
171
|
+
.pipe(Effect.map((result) => mapEnvelopeToRemoteRequest(baseUrl, result)));
|
|
172
|
+
const listEnvelopes = (http, options, baseUrl) => http
|
|
173
|
+
.requestJson({
|
|
174
|
+
provider: PROVIDER,
|
|
175
|
+
method: "GET",
|
|
176
|
+
url: `${baseUrl}/envelope`,
|
|
177
|
+
headers: { Authorization: documensoAuthorization(options) },
|
|
178
|
+
}, DocumensoEnvelopeListResultSchema, SignatureKitSchemaNameValue.documensoEnvelopeListResult)
|
|
179
|
+
.pipe(Effect.map((result) => result.data.map((envelope) => mapEnvelopeToRemoteRequest(baseUrl, envelope))));
|
|
180
|
+
const cancelEnvelope = (http, options, baseUrl, envelopeId) => http.requestVoid({
|
|
181
|
+
provider: PROVIDER,
|
|
182
|
+
method: "POST",
|
|
183
|
+
url: `${baseUrl}/envelope/cancel`,
|
|
184
|
+
headers: {
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
Authorization: documensoAuthorization(options),
|
|
187
|
+
},
|
|
188
|
+
body: JSON.stringify({ envelopeId }),
|
|
189
|
+
});
|
|
190
|
+
const deleteEnvelope = (http, options, baseUrl, envelopeId) => http
|
|
191
|
+
.requestVoid({
|
|
192
|
+
provider: PROVIDER,
|
|
193
|
+
method: "POST",
|
|
194
|
+
url: `${baseUrl}/envelope/delete`,
|
|
195
|
+
headers: {
|
|
196
|
+
"Content-Type": "application/json",
|
|
197
|
+
Authorization: documensoAuthorization(options),
|
|
198
|
+
},
|
|
199
|
+
body: JSON.stringify({ envelopeId }),
|
|
200
|
+
})
|
|
201
|
+
.pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.void));
|
|
202
|
+
const downloadSignedEnvelopeItem = (http, options, baseUrl, envelopeItemId) => {
|
|
203
|
+
const url = new URL(`${baseUrl}/envelope/item/${envelopeItemId}/download`);
|
|
204
|
+
url.searchParams.set("version", "signed");
|
|
205
|
+
return http.requestBytes({
|
|
206
|
+
provider: PROVIDER,
|
|
207
|
+
method: "GET",
|
|
208
|
+
url: url.toString(),
|
|
209
|
+
headers: { Authorization: documensoAuthorization(options) },
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
const downloadSignedEnvelopeDocument = (http, options, baseUrl, envelopeId) => getEnvelope(http, options, baseUrl, envelopeId).pipe(Effect.flatMap((request) => request.downloadUrl === undefined
|
|
213
|
+
? downloadSignedEnvelopeItem(http, options, baseUrl, envelopeId)
|
|
214
|
+
: http.requestBytes({
|
|
215
|
+
provider: PROVIDER,
|
|
216
|
+
method: "GET",
|
|
217
|
+
url: request.downloadUrl,
|
|
218
|
+
headers: { Authorization: documensoAuthorization(options) },
|
|
219
|
+
})), Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => downloadSignedEnvelopeItem(http, options, baseUrl, envelopeId)));
|
|
220
|
+
const createRemoteRequest = (http, options, baseUrl, input) => createEnvelope(http, options, baseUrl, input).pipe(Effect.flatMap((envelope) => {
|
|
221
|
+
if (input.send !== false)
|
|
222
|
+
return distributeEnvelope(http, options, baseUrl, input, envelope);
|
|
223
|
+
return Effect.succeed({
|
|
224
|
+
provider: PROVIDER,
|
|
225
|
+
id: envelope.id,
|
|
226
|
+
state: "draft",
|
|
227
|
+
providerStatus: "DRAFT",
|
|
228
|
+
detailsUrl: `${baseUrl}/envelope/${envelope.id}`,
|
|
229
|
+
});
|
|
230
|
+
}));
|
|
231
|
+
export const DocumensoSignatureRequestProvider = () => Provider.effect(DocumensoSignatureRequest, Effect.gen(function* () {
|
|
232
|
+
const options = yield* DocumensoCredentials;
|
|
233
|
+
const http = yield* SignatureHttpClient;
|
|
234
|
+
const baseUrl = documensoBaseUrl(options);
|
|
235
|
+
return DocumensoSignatureRequest.Provider.of({
|
|
236
|
+
diff: ({ olds }) => Effect.succeed(olds === undefined ? undefined : { action: "noop" }),
|
|
237
|
+
list: () => listEnvelopes(http, options, baseUrl),
|
|
238
|
+
read: ({ output }) => output === undefined
|
|
239
|
+
? Effect.succeed(undefined)
|
|
240
|
+
: getEnvelope(http, options, baseUrl, output.id).pipe(Effect.catchIf((error) => error.code === SignatureKitErrorCodeValue.http && error.status === 404, () => Effect.succeed(undefined))),
|
|
241
|
+
reconcile: Effect.fn(function* ({ news, output }) {
|
|
242
|
+
if (output !== undefined)
|
|
243
|
+
return output;
|
|
244
|
+
const input = yield* remoteSignatureInputFromResourceProps(PROVIDER, news);
|
|
245
|
+
return yield* createRemoteRequest(http, options, baseUrl, input);
|
|
246
|
+
}),
|
|
247
|
+
delete: ({ output }) => deleteEnvelope(http, options, baseUrl, output.id),
|
|
248
|
+
});
|
|
249
|
+
}));
|
|
250
|
+
export class DocumensoProviders extends Provider.ProviderCollection()(DOCUMENSO_PROVIDER_COLLECTION_ID) {
|
|
251
|
+
}
|
|
252
|
+
export const providers = (options) => Layer.effect(DocumensoProviders, Provider.collection([DocumensoSignatureRequest])).pipe(Layer.provide(DocumensoSignatureRequestProvider()), Layer.provide(documensoCredentialsLayer(options)));
|
|
253
|
+
export const getDocumensoSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
254
|
+
const valid = yield* Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
255
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
256
|
+
retryable: false,
|
|
257
|
+
provider: PROVIDER,
|
|
258
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
259
|
+
schemaName: SignatureKitSchemaNameValue.documensoProviderOptions,
|
|
260
|
+
issueMessage: String(issue),
|
|
261
|
+
})));
|
|
262
|
+
const http = yield* SignatureHttpClient;
|
|
263
|
+
return yield* getEnvelope(http, valid, documensoBaseUrl(valid), id);
|
|
264
|
+
});
|
|
265
|
+
export const listDocumensoSignatureRequests = (options) => Effect.gen(function* () {
|
|
266
|
+
const valid = yield* Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
267
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
268
|
+
retryable: false,
|
|
269
|
+
provider: PROVIDER,
|
|
270
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
271
|
+
schemaName: SignatureKitSchemaNameValue.documensoProviderOptions,
|
|
272
|
+
issueMessage: String(issue),
|
|
273
|
+
})));
|
|
274
|
+
const http = yield* SignatureHttpClient;
|
|
275
|
+
return yield* listEnvelopes(http, valid, documensoBaseUrl(valid));
|
|
276
|
+
});
|
|
277
|
+
export const cancelDocumensoSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
278
|
+
const valid = yield* Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
279
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
280
|
+
retryable: false,
|
|
281
|
+
provider: PROVIDER,
|
|
282
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
283
|
+
schemaName: SignatureKitSchemaNameValue.documensoProviderOptions,
|
|
284
|
+
issueMessage: String(issue),
|
|
285
|
+
})));
|
|
286
|
+
const http = yield* SignatureHttpClient;
|
|
287
|
+
return yield* cancelEnvelope(http, valid, documensoBaseUrl(valid), id);
|
|
288
|
+
});
|
|
289
|
+
export const deleteDocumensoSignatureRequest = (options, id) => Effect.gen(function* () {
|
|
290
|
+
const valid = yield* Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
291
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
292
|
+
retryable: false,
|
|
293
|
+
provider: PROVIDER,
|
|
294
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
295
|
+
schemaName: SignatureKitSchemaNameValue.documensoProviderOptions,
|
|
296
|
+
issueMessage: String(issue),
|
|
297
|
+
})));
|
|
298
|
+
const http = yield* SignatureHttpClient;
|
|
299
|
+
return yield* deleteEnvelope(http, valid, documensoBaseUrl(valid), id);
|
|
300
|
+
});
|
|
301
|
+
export const downloadDocumensoSignedDocument = (options, envelopeId) => Effect.gen(function* () {
|
|
302
|
+
const valid = yield* Schema.decodeUnknownEffect(DocumensoProviderOptionsSchema)(options).pipe(Effect.mapError((issue) => new SignatureKitError({
|
|
303
|
+
code: SignatureKitErrorCodeValue.invalidInput,
|
|
304
|
+
retryable: false,
|
|
305
|
+
provider: PROVIDER,
|
|
306
|
+
operation: SignatureKitOperationValue.schemaDecode,
|
|
307
|
+
schemaName: SignatureKitSchemaNameValue.documensoProviderOptions,
|
|
308
|
+
issueMessage: String(issue),
|
|
309
|
+
})));
|
|
310
|
+
const http = yield* SignatureHttpClient;
|
|
311
|
+
return yield* downloadSignedEnvelopeDocument(http, valid, documensoBaseUrl(valid), envelopeId);
|
|
312
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signature-kit/documenso",
|
|
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
|
+
"alchemy": "2.0.0-beta.57",
|
|
32
|
+
"effect": "4.0.0-beta.86"
|
|
33
|
+
},
|
|
34
|
+
"nx": {
|
|
35
|
+
"targets": {
|
|
36
|
+
"npm-pack": {
|
|
37
|
+
"executor": "nx:run-commands",
|
|
38
|
+
"options": {
|
|
39
|
+
"command": "npm pack --dry-run --json",
|
|
40
|
+
"cwd": "{projectRoot}"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"npm-publish": {
|
|
44
|
+
"executor": "nx:run-commands",
|
|
45
|
+
"options": {
|
|
46
|
+
"command": "npm publish --access public",
|
|
47
|
+
"cwd": "{projectRoot}"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|