@keystrokehq/docusign 0.0.16-integration-id-canonicalization.0 → 0.0.16

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.
@@ -1,4 +1,4 @@
1
- import { n as DOCUSIGN_USERINFO_URL, r as fetchDocusignUserinfo, t as docusignCredentialSet } from "./docusign.credential-set-DRhK9ICD.mjs";
1
+ import { n as DOCUSIGN_USERINFO_URL, r as fetchDocusignUserinfo, t as docusignCredentialSet } from "./docusign.credential-set-BloJ2PrK.mjs";
2
2
  import { docusignAccountSchema, docusignBrandListSchema, docusignBulkSendBatchSchema, docusignBulkSendListSchema, docusignConnectConfigurationSchema, docusignCustomFieldsInputSchema, docusignCustomFieldsResponseSchema, docusignDocumentIdSchema, docusignDocumentListSchema, docusignEnvelopeCreateInputSchema, docusignEnvelopeIdSchema, docusignEnvelopeSchema, docusignEnvelopeSummarySchema, docusignGenericObjectSchema, docusignGroupListSchema, docusignIncludeSchema, docusignListPaginationInputSchema, docusignLooseObjectSchema, docusignRecipientIdSchema, docusignSuccessSchema, docusignTemplateIdSchema, docusignTemplateListSchema, docusignTemplateSchema, docusignUserListSchema, docusignUserSchema } from "./schemas/index.mjs";
3
3
  import { Operation } from "@keystrokehq/core";
4
4
  import { z } from "zod";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keystrokehq/docusign",
3
- "version": "0.0.16-integration-id-canonicalization.0",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -40,9 +40,8 @@
40
40
  "vitest": "^4.0.18",
41
41
  "@keystrokehq/core": "^0.0.12",
42
42
  "@keystrokehq/test-utils": "0.0.0",
43
- "@keystrokehq/integration-authoring": "0.0.9",
44
- "@keystrokehq/credential-connection": "1.0.0",
45
- "@keystrokehq/typescript-config": "0.0.0"
43
+ "@keystrokehq/typescript-config": "0.0.0",
44
+ "@keystrokehq/integration-authoring": "0.0.9"
46
45
  },
47
46
  "keywords": [
48
47
  "docusign",
@@ -1,183 +0,0 @@
1
- import { CredentialSet } from "@keystrokehq/core";
2
- import { z } from "zod";
3
-
4
- //#region ../../packages/credential-connection/src/token.ts
5
- /**
6
- * Shared OAuth 2.0 token-response plumbing.
7
- *
8
- * `parseOAuthTokenResponse` handles the two common wire formats (JSON and
9
- * form-urlencoded, the latter used by GitHub unless you explicitly ask for
10
- * JSON). `normalizeOAuthTokens` pulls the standard fields out of the parsed
11
- * body in both the flat form and Slack's nested `authed_user.access_token`
12
- * form. These helpers are exposed so integration authors overriding
13
- * `exchangeCode` / `refreshToken` do not have to re-implement them.
14
- */
15
- var TokenExchangeError = class extends Error {
16
- httpStatus;
17
- constructor(httpStatus) {
18
- super(`Token exchange failed: HTTP ${httpStatus}`);
19
- this.name = "TokenExchangeError";
20
- this.httpStatus = httpStatus;
21
- }
22
- };
23
- async function parseOAuthTokenResponse(response) {
24
- const contentType = response.headers.get("content-type")?.toLowerCase() ?? "";
25
- if (contentType.includes("application/json")) return await response.json();
26
- const text = await response.text();
27
- if (!text.trim()) return {};
28
- if (contentType.includes("application/x-www-form-urlencoded") || text.includes("=")) {
29
- const params = new URLSearchParams(text);
30
- return Object.fromEntries(params.entries());
31
- }
32
- throw new Error(`Unsupported OAuth token response content type: ${contentType || "unknown"}`);
33
- }
34
- function normalizeOAuthTokens(tokenData) {
35
- const authedUser = tokenData.authed_user;
36
- const rawAccessToken = tokenData.access_token ?? authedUser?.access_token;
37
- const rawRefreshToken = tokenData.refresh_token;
38
- const rawExpiresIn = tokenData.expires_in;
39
- const rawInstanceUrl = tokenData.instance_url;
40
- return {
41
- accessToken: typeof rawAccessToken === "string" ? rawAccessToken : void 0,
42
- refreshToken: typeof rawRefreshToken === "string" ? rawRefreshToken : void 0,
43
- expiresIn: typeof rawExpiresIn === "number" ? rawExpiresIn : typeof rawExpiresIn === "string" ? Number(rawExpiresIn) || void 0 : void 0,
44
- instanceUrl: typeof rawInstanceUrl === "string" ? rawInstanceUrl : void 0
45
- };
46
- }
47
-
48
- //#endregion
49
- //#region src/utils/oauth-connection.ts
50
- const DOCUSIGN_OAUTH_HOST = "account.docusign.com";
51
- const DOCUSIGN_AUTH_URL = `https://${DOCUSIGN_OAUTH_HOST}/oauth/auth`;
52
- const DOCUSIGN_TOKEN_URL = `https://${DOCUSIGN_OAUTH_HOST}/oauth/token`;
53
- const DOCUSIGN_REVOKE_URL = `https://${DOCUSIGN_OAUTH_HOST}/oauth/revoke`;
54
- const DOCUSIGN_USERINFO_URL = `https://${DOCUSIGN_OAUTH_HOST}/oauth/userinfo`;
55
- const DOCUSIGN_OAUTH_SCOPES = ["signature", "extended"];
56
- function basicAuthHeader(clientId, clientSecret) {
57
- return `Basic ${Buffer.from(`${clientId}:${clientSecret}`, "utf8").toString("base64")}`;
58
- }
59
- async function postDocusignToken(body, authHeader) {
60
- const response = await fetch(DOCUSIGN_TOKEN_URL, {
61
- method: "POST",
62
- headers: {
63
- Accept: "application/json",
64
- "Content-Type": "application/x-www-form-urlencoded",
65
- Authorization: authHeader
66
- },
67
- body
68
- });
69
- if (!response.ok) throw new TokenExchangeError(response.status);
70
- const raw = await parseOAuthTokenResponse(response);
71
- const { accessToken, refreshToken, expiresIn } = normalizeOAuthTokens(raw);
72
- if (!accessToken) throw new Error("No access token in DocuSign response");
73
- return {
74
- accessToken,
75
- refreshToken,
76
- expiresIn,
77
- raw
78
- };
79
- }
80
- async function fetchDocusignUserinfo(accessToken) {
81
- const response = await fetch(DOCUSIGN_USERINFO_URL, { headers: {
82
- Accept: "application/json",
83
- Authorization: `Bearer ${accessToken}`
84
- } });
85
- if (!response.ok) throw new Error(`DocuSign userinfo lookup failed with status ${response.status} while resolving base URI.`);
86
- return await response.json();
87
- }
88
- function pickDefaultAccount(userinfo) {
89
- const accounts = userinfo.accounts ?? [];
90
- if (accounts.length === 0) return void 0;
91
- const explicitDefault = accounts.find((account) => account.is_default === true && typeof account.account_id === "string" && typeof account.base_uri === "string");
92
- if (explicitDefault) return {
93
- accountId: explicitDefault.account_id,
94
- baseUri: explicitDefault.base_uri
95
- };
96
- const firstWithBoth = accounts.find((account) => typeof account.account_id === "string" && typeof account.base_uri === "string");
97
- if (firstWithBoth) return {
98
- accountId: firstWithBoth.account_id,
99
- baseUri: firstWithBoth.base_uri
100
- };
101
- }
102
- const docusignOAuthConnection = {
103
- kind: "oauth",
104
- tokenType: "refreshable",
105
- authUrl: DOCUSIGN_AUTH_URL,
106
- tokenUrl: DOCUSIGN_TOKEN_URL,
107
- revokeUrl: DOCUSIGN_REVOKE_URL,
108
- scopes: [...DOCUSIGN_OAUTH_SCOPES],
109
- oauth: { id: "official.docusign.oauth" },
110
- vault: {
111
- accessTokenKey: "DOCUSIGN_ACCESS_TOKEN",
112
- build: (tokenResult) => {
113
- const accountId = typeof tokenResult.raw._docusignAccountId === "string" ? tokenResult.raw._docusignAccountId : void 0;
114
- const baseUri = typeof tokenResult.raw._docusignBaseUri === "string" ? tokenResult.raw._docusignBaseUri : void 0;
115
- return {
116
- DOCUSIGN_ACCESS_TOKEN: tokenResult.accessToken,
117
- ...accountId ? { DOCUSIGN_ACCOUNT_ID: accountId } : {},
118
- ...baseUri ? { DOCUSIGN_BASE_URI: baseUri } : {}
119
- };
120
- }
121
- },
122
- async exchangeCode({ oauthClient, code, redirectUri }) {
123
- if (!code) throw new Error("Missing authorization code");
124
- const tokenResult = await postDocusignToken(new URLSearchParams({
125
- grant_type: "authorization_code",
126
- code,
127
- redirect_uri: redirectUri
128
- }), basicAuthHeader(oauthClient.clientId, oauthClient.clientSecret));
129
- const userinfo = await fetchDocusignUserinfo(tokenResult.accessToken);
130
- const account = pickDefaultAccount(userinfo);
131
- if (!account) throw new Error("DocuSign userinfo response did not include a resolvable account.");
132
- tokenResult.raw._docusignAccountId = account.accountId;
133
- tokenResult.raw._docusignBaseUri = account.baseUri;
134
- tokenResult.raw._docusignUserinfo = userinfo;
135
- return tokenResult;
136
- },
137
- async refreshToken({ oauthClient, refreshToken }) {
138
- const tokenResult = await postDocusignToken(new URLSearchParams({
139
- grant_type: "refresh_token",
140
- refresh_token: refreshToken
141
- }), basicAuthHeader(oauthClient.clientId, oauthClient.clientSecret));
142
- const userinfo = await fetchDocusignUserinfo(tokenResult.accessToken);
143
- const account = pickDefaultAccount(userinfo);
144
- if (!account) throw new Error("DocuSign userinfo response did not include a resolvable account during refresh.");
145
- tokenResult.raw._docusignAccountId = account.accountId;
146
- tokenResult.raw._docusignBaseUri = account.baseUri;
147
- tokenResult.raw._docusignUserinfo = userinfo;
148
- return tokenResult;
149
- },
150
- extractInstallationInfo({ tokenResult }) {
151
- const accountId = typeof tokenResult.raw._docusignAccountId === "string" ? tokenResult.raw._docusignAccountId : void 0;
152
- const baseUri = typeof tokenResult.raw._docusignBaseUri === "string" ? tokenResult.raw._docusignBaseUri : void 0;
153
- return {
154
- externalInstallationId: accountId,
155
- externalWorkspaceId: accountId,
156
- metadata: accountId && baseUri ? {
157
- accountId,
158
- baseUri
159
- } : void 0
160
- };
161
- }
162
- };
163
-
164
- //#endregion
165
- //#region src/credential-sets/docusign.credential-set.ts
166
- const docusignAuthSchema = z.object({
167
- DOCUSIGN_ACCESS_TOKEN: z.string().min(1),
168
- DOCUSIGN_ACCOUNT_ID: z.string().min(1),
169
- DOCUSIGN_BASE_URI: z.url()
170
- });
171
- const docusignCredentialSet = new CredentialSet({
172
- id: "docusign",
173
- name: "DocuSign",
174
- description: "DocuSign eSignature, templates, bulk-send, Connect webhooks, and account/admin surfaces for Keystroke workflows",
175
- auth: docusignAuthSchema,
176
- connections: [{
177
- id: "oauth",
178
- ...docusignOAuthConnection
179
- }]
180
- });
181
-
182
- //#endregion
183
- export { DOCUSIGN_USERINFO_URL as n, fetchDocusignUserinfo as r, docusignCredentialSet as t };