@slates/provider 1.0.0-rc.15 → 1.0.0-rc.17
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/dist/index.cjs +414 -5
- package/dist/index.d.cts +190 -1
- package/dist/index.d.ts +190 -1
- package/dist/index.module.js +388 -2
- package/package.json +2 -2
- package/src/action/action.ts +50 -1
- package/src/action/builder.ts +26 -2
- package/src/action/trigger.ts +9 -1
- package/src/auth/index.ts +1 -0
- package/src/auth/oauth.test.ts +83 -0
- package/src/auth/oauth.ts +150 -0
- package/src/auth/types.ts +31 -6
- package/src/axios/http.test.ts +83 -0
- package/src/axios/index.ts +59 -1
- package/src/context/context.ts +8 -0
- package/src/crypto/hmac.test.ts +40 -0
- package/src/crypto/hmac.ts +32 -0
- package/src/crypto/index.ts +1 -0
- package/src/error/api.test.ts +114 -0
- package/src/error/api.ts +236 -0
- package/src/error/index.ts +1 -0
- package/src/file/index.test.ts +36 -0
- package/src/file/index.ts +27 -0
- package/src/index.ts +4 -0
- package/src/object/index.test.ts +38 -0
- package/src/object/index.ts +12 -0
- package/src/webhook/graph.test.ts +37 -0
- package/src/webhook/graph.ts +22 -0
- package/src/webhook/index.ts +2 -0
- package/src/webhook/meta.test.ts +52 -0
- package/src/webhook/meta.ts +43 -0
package/dist/index.cjs
CHANGED
|
@@ -46,26 +46,49 @@ __export(index_exports, {
|
|
|
46
46
|
anyOf: () => anyOf,
|
|
47
47
|
auth: () => auth,
|
|
48
48
|
axios: () => axios,
|
|
49
|
+
buildApiServiceError: () => buildApiServiceError,
|
|
50
|
+
collectApiErrorDetails: () => collectApiErrorDetails,
|
|
49
51
|
config: () => config,
|
|
52
|
+
createApiServiceError: () => createApiServiceError,
|
|
53
|
+
createAuthenticatedAxios: () => createAuthenticatedAxios,
|
|
50
54
|
createAxios: () => createAxios,
|
|
51
55
|
createBase64Attachment: () => createBase64Attachment,
|
|
56
|
+
createHmacSignature: () => createHmacSignature,
|
|
52
57
|
createSlateError: () => createSlateError,
|
|
53
58
|
createTextAttachment: () => createTextAttachment,
|
|
54
59
|
createUrlAttachment: () => createUrlAttachment,
|
|
60
|
+
extractApiErrorMessage: () => extractApiErrorMessage,
|
|
61
|
+
getApiErrorResponse: () => getApiErrorResponse,
|
|
62
|
+
getApiErrorStatus: () => getApiErrorStatus,
|
|
63
|
+
getBase64ByteLength: () => getBase64ByteLength,
|
|
55
64
|
getCurrentContext: () => getCurrentContext,
|
|
65
|
+
getGraphWebhookValidationResponse: () => getGraphWebhookValidationResponse,
|
|
66
|
+
getMetaWebhookVerificationResponse: () => getMetaWebhookVerificationResponse,
|
|
67
|
+
getOAuthExpiresAtFromExpiresIn: () => getOAuthExpiresAtFromExpiresIn,
|
|
68
|
+
getResponseHeaderValue: () => getResponseHeaderValue,
|
|
56
69
|
getServiceErrorData: () => getServiceErrorData,
|
|
70
|
+
graphWebhookHttp: () => graphWebhookHttp,
|
|
57
71
|
inferSlateErrorFromAxios: () => inferSlateErrorFromAxios,
|
|
72
|
+
isApiErrorRecord: () => isApiErrorRecord,
|
|
58
73
|
isAxiosErrorLike: () => isAxiosErrorLike,
|
|
59
74
|
isServiceErrorData: () => isServiceErrorData,
|
|
60
75
|
mapServiceErrorCode: () => mapServiceErrorCode,
|
|
61
76
|
mapServiceErrorToSlateErrorInput: () => mapServiceErrorToSlateErrorInput,
|
|
62
77
|
mergeScopes: () => mergeScopes,
|
|
78
|
+
metaWebhookHttp: () => metaWebhookHttp,
|
|
79
|
+
normalizeOAuthTokenResponse: () => normalizeOAuthTokenResponse,
|
|
80
|
+
pickDefined: () => pickDefined,
|
|
81
|
+
requestAxios: () => requestAxios,
|
|
82
|
+
requestAxiosData: () => requestAxiosData,
|
|
63
83
|
runWithContext: () => runWithContext,
|
|
64
84
|
scopeClause: () => scopeClause,
|
|
85
|
+
setIfDefined: () => setIfDefined,
|
|
65
86
|
spec: () => spec,
|
|
87
|
+
statusLabelForApiError: () => statusLabelForApiError,
|
|
66
88
|
tool: () => tool,
|
|
67
89
|
trigger: () => trigger,
|
|
68
|
-
validateScopes: () => validateScopes
|
|
90
|
+
validateScopes: () => validateScopes,
|
|
91
|
+
verifyHmacSignature: () => verifyHmacSignature
|
|
69
92
|
});
|
|
70
93
|
module.exports = __toCommonJS(index_exports);
|
|
71
94
|
|
|
@@ -119,11 +142,132 @@ var SlateAction = class {
|
|
|
119
142
|
get scopes() {
|
|
120
143
|
return this._params.scopes;
|
|
121
144
|
}
|
|
145
|
+
get authMethods() {
|
|
146
|
+
return this._params.authMethods;
|
|
147
|
+
}
|
|
122
148
|
get docs() {
|
|
123
149
|
return this._params.docs;
|
|
124
150
|
}
|
|
125
151
|
};
|
|
126
152
|
|
|
153
|
+
// src/error/api.ts
|
|
154
|
+
var import_error = require("@lowerdeck/error");
|
|
155
|
+
var DEFAULT_DETAIL_KEYS = ["message", "detail", "error", "error_description", "code"];
|
|
156
|
+
var DEFAULT_NESTED_KEYS = ["errors"];
|
|
157
|
+
var isApiErrorRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
158
|
+
var pushDetail = (details, value, options = {}) => {
|
|
159
|
+
if (typeof value !== "string" && (options.includeNumbers === false || typeof value !== "number")) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
let detail = String(value).trim();
|
|
163
|
+
if (detail && !details.includes(detail)) {
|
|
164
|
+
details.push(detail);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var collectApiErrorDetails = (value, details, options = {}) => {
|
|
168
|
+
if (Array.isArray(value)) {
|
|
169
|
+
for (let item of value) {
|
|
170
|
+
collectApiErrorDetails(item, details, options);
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (!isApiErrorRecord(value)) {
|
|
175
|
+
pushDetail(details, value, options);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
for (let key of options.detailKeys ?? DEFAULT_DETAIL_KEYS) {
|
|
179
|
+
pushDetail(details, value[key], options);
|
|
180
|
+
}
|
|
181
|
+
for (let key of options.nestedKeys ?? DEFAULT_NESTED_KEYS) {
|
|
182
|
+
collectApiErrorDetails(value[key], details, options);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var getSlateErrorResponse = (error) => {
|
|
186
|
+
if (error.name !== "SlateError" || !isApiErrorRecord(error.data)) {
|
|
187
|
+
return void 0;
|
|
188
|
+
}
|
|
189
|
+
let data = error.data;
|
|
190
|
+
let upstream = isApiErrorRecord(data.upstream) ? data.upstream : void 0;
|
|
191
|
+
let status = upstream?.status ?? data.status;
|
|
192
|
+
return typeof status === "number" || typeof status === "string" ? { status } : void 0;
|
|
193
|
+
};
|
|
194
|
+
var getApiErrorResponse = (error) => {
|
|
195
|
+
if (!isApiErrorRecord(error)) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
if (!isApiErrorRecord(error.response)) {
|
|
199
|
+
return getSlateErrorResponse(error);
|
|
200
|
+
}
|
|
201
|
+
let response = error.response;
|
|
202
|
+
return {
|
|
203
|
+
status: typeof response.status === "number" || typeof response.status === "string" ? response.status : void 0,
|
|
204
|
+
statusText: typeof response.statusText === "string" ? response.statusText : void 0,
|
|
205
|
+
data: response.data
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
var getApiErrorStatus = (error) => getApiErrorResponse(error)?.status;
|
|
209
|
+
var statusLabelForApiError = (status, statusText) => status !== void 0 ? `HTTP ${status}${statusText ? ` ${statusText}` : ""}: ` : "";
|
|
210
|
+
var extractApiErrorMessage = (error, options = {}) => {
|
|
211
|
+
let details = [];
|
|
212
|
+
let response = options.response ?? getApiErrorResponse(error);
|
|
213
|
+
collectApiErrorDetails(response?.data, details, options);
|
|
214
|
+
if (details.length > 0) {
|
|
215
|
+
return details.join(options.separator ?? " - ");
|
|
216
|
+
}
|
|
217
|
+
if (error instanceof Error && error.message) {
|
|
218
|
+
return error.message;
|
|
219
|
+
}
|
|
220
|
+
return options.fallbackMessage ?? "Unknown error";
|
|
221
|
+
};
|
|
222
|
+
var createApiServiceError = (message, options = {}) => {
|
|
223
|
+
let error = new import_error.ServiceError((0, import_error.badRequestError)({ message }));
|
|
224
|
+
if (options.reason !== void 0) {
|
|
225
|
+
error.data.reason = options.reason;
|
|
226
|
+
}
|
|
227
|
+
if ("upstreamStatus" in options) {
|
|
228
|
+
error.data.upstreamStatus = options.upstreamStatus;
|
|
229
|
+
}
|
|
230
|
+
if ("upstreamCode" in options) {
|
|
231
|
+
error.data.upstreamCode = options.upstreamCode;
|
|
232
|
+
}
|
|
233
|
+
if (options.parent instanceof Error) {
|
|
234
|
+
error.setParent(options.parent);
|
|
235
|
+
}
|
|
236
|
+
return error;
|
|
237
|
+
};
|
|
238
|
+
var helpers = {
|
|
239
|
+
collectDetails: collectApiErrorDetails,
|
|
240
|
+
extractMessage: extractApiErrorMessage,
|
|
241
|
+
getResponse: getApiErrorResponse,
|
|
242
|
+
getStatus: getApiErrorStatus,
|
|
243
|
+
isRecord: isApiErrorRecord,
|
|
244
|
+
statusLabelFor: statusLabelForApiError
|
|
245
|
+
};
|
|
246
|
+
var buildApiServiceError = (error, options) => {
|
|
247
|
+
if (error instanceof import_error.ServiceError) {
|
|
248
|
+
return error;
|
|
249
|
+
}
|
|
250
|
+
let operation = options.operation ?? "request";
|
|
251
|
+
let response = options.extractResponse?.(error, helpers) ?? getApiErrorResponse(error);
|
|
252
|
+
let status = options.extractStatus?.(error, response, helpers) ?? response?.status;
|
|
253
|
+
let message = options.extractMessage?.(error, helpers) ?? extractApiErrorMessage(error, { ...options, response });
|
|
254
|
+
let statusLabel = statusLabelForApiError(status, response?.statusText);
|
|
255
|
+
let fullMessage = options.formatMessage?.({
|
|
256
|
+
providerLabel: options.providerLabel,
|
|
257
|
+
operation,
|
|
258
|
+
statusLabel,
|
|
259
|
+
message,
|
|
260
|
+
response,
|
|
261
|
+
status
|
|
262
|
+
}) ?? `${options.providerLabel} API ${operation} failed: ${statusLabel}${message}`;
|
|
263
|
+
return createApiServiceError(fullMessage, {
|
|
264
|
+
reason: options.reason,
|
|
265
|
+
upstreamStatus: status,
|
|
266
|
+
upstreamCode: options.extractUpstreamCode?.(error, response, helpers),
|
|
267
|
+
parent: options.parent ?? error
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
|
|
127
271
|
// src/error/axios.ts
|
|
128
272
|
var import_axios = require("axios");
|
|
129
273
|
|
|
@@ -465,7 +609,7 @@ var inferSlateErrorFromAxios = (error, options = {}) => {
|
|
|
465
609
|
};
|
|
466
610
|
|
|
467
611
|
// src/error/service.ts
|
|
468
|
-
var
|
|
612
|
+
var import_error2 = require("@lowerdeck/error");
|
|
469
613
|
var SERVICE_ERROR_DATA_RESERVED_KEYS = /* @__PURE__ */ new Set([
|
|
470
614
|
"status",
|
|
471
615
|
"code",
|
|
@@ -532,7 +676,7 @@ var getServiceErrorBaggage = (data) => {
|
|
|
532
676
|
var mapServiceErrorCode = (code, status) => SERVICE_ERROR_CODE_MAP[code] ?? mapServiceErrorCodeByStatus(status);
|
|
533
677
|
var isServiceErrorData = (value) => isRecord(value) && typeof value.status === "number" && typeof value.code === "string" && typeof value.message === "string" && !("config" in value) && !("request" in value) && !("response" in value) && !("isAxiosError" in value);
|
|
534
678
|
var getServiceErrorData = (error) => {
|
|
535
|
-
if ((0,
|
|
679
|
+
if ((0, import_error2.isServiceError)(error)) {
|
|
536
680
|
return isServiceErrorData(error.data) ? error.data : null;
|
|
537
681
|
}
|
|
538
682
|
if (isServiceErrorData(error)) {
|
|
@@ -765,6 +909,7 @@ var SlateActionBuilder = class {
|
|
|
765
909
|
#inputSchema = null;
|
|
766
910
|
#outputSchema = null;
|
|
767
911
|
#scopes;
|
|
912
|
+
#authMethods;
|
|
768
913
|
#toolParams = null;
|
|
769
914
|
#triggerParams = null;
|
|
770
915
|
input(schema) {
|
|
@@ -780,6 +925,18 @@ var SlateActionBuilder = class {
|
|
|
780
925
|
this.#scopes = scopes;
|
|
781
926
|
return this;
|
|
782
927
|
}
|
|
928
|
+
authMethods(authMethods) {
|
|
929
|
+
this.#authMethods = this.validateAuthMethods(authMethods);
|
|
930
|
+
return this;
|
|
931
|
+
}
|
|
932
|
+
validateAuthMethods(authMethods) {
|
|
933
|
+
if (!authMethods) return void 0;
|
|
934
|
+
let normalized = [...new Set(authMethods.map((authMethod) => authMethod.trim()))];
|
|
935
|
+
if (normalized.some((authMethod) => !authMethod)) {
|
|
936
|
+
throw new SlateDeclarationError("Auth method IDs must be non-empty strings");
|
|
937
|
+
}
|
|
938
|
+
return normalized;
|
|
939
|
+
}
|
|
783
940
|
handleInvocation(handler) {
|
|
784
941
|
if (this.type !== "tool") {
|
|
785
942
|
throw new SlateDeclarationError("handleInvocation can only be set for tool actions");
|
|
@@ -800,7 +957,8 @@ var SlateActionBuilder = class {
|
|
|
800
957
|
handleEvent: props.handleEvent,
|
|
801
958
|
handleRequest: props.handleRequest,
|
|
802
959
|
autoRegisterWebhook: props.autoRegisterWebhook,
|
|
803
|
-
autoUnregisterWebhook: props.autoUnregisterWebhook
|
|
960
|
+
autoUnregisterWebhook: props.autoUnregisterWebhook,
|
|
961
|
+
http: props.http
|
|
804
962
|
};
|
|
805
963
|
return this;
|
|
806
964
|
}
|
|
@@ -822,6 +980,7 @@ var SlateActionBuilder = class {
|
|
|
822
980
|
if (scopes) {
|
|
823
981
|
validateScopes(scopes);
|
|
824
982
|
}
|
|
983
|
+
let authMethods = this.validateAuthMethods(this.#authMethods ?? this.params.authMethods);
|
|
825
984
|
if (!this.#inputSchema) {
|
|
826
985
|
throw new SlateDeclarationError("Input schema is not defined");
|
|
827
986
|
}
|
|
@@ -837,6 +996,7 @@ var SlateActionBuilder = class {
|
|
|
837
996
|
return this.factory({
|
|
838
997
|
...this.params,
|
|
839
998
|
scopes,
|
|
999
|
+
authMethods,
|
|
840
1000
|
configSchema: this.#configSchema,
|
|
841
1001
|
authSchema: this.#authSchema,
|
|
842
1002
|
inputSchema: this.#inputSchema,
|
|
@@ -873,6 +1033,7 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
873
1033
|
#polling;
|
|
874
1034
|
#handleEvent;
|
|
875
1035
|
#handleRequest;
|
|
1036
|
+
#http;
|
|
876
1037
|
#pollEvents;
|
|
877
1038
|
#autoRegisterWebhook;
|
|
878
1039
|
#autoUnregisterWebhook;
|
|
@@ -884,6 +1045,7 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
884
1045
|
};
|
|
885
1046
|
this.#handleEvent = params.handleEvent;
|
|
886
1047
|
this.#handleRequest = params.handleRequest;
|
|
1048
|
+
this.#http = params.http;
|
|
887
1049
|
this.#pollEvents = params.pollEvents;
|
|
888
1050
|
this.#autoRegisterWebhook = params.autoRegisterWebhook;
|
|
889
1051
|
this.#autoUnregisterWebhook = params.autoUnregisterWebhook;
|
|
@@ -906,6 +1068,9 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
906
1068
|
get handleRequest() {
|
|
907
1069
|
return this.#handleRequest;
|
|
908
1070
|
}
|
|
1071
|
+
get http() {
|
|
1072
|
+
return this.#http;
|
|
1073
|
+
}
|
|
909
1074
|
get pollEvents() {
|
|
910
1075
|
return this.#pollEvents;
|
|
911
1076
|
}
|
|
@@ -1000,6 +1165,90 @@ var SlateAuth = class _SlateAuth {
|
|
|
1000
1165
|
};
|
|
1001
1166
|
var auth = () => SlateAuth.create();
|
|
1002
1167
|
|
|
1168
|
+
// src/auth/oauth.ts
|
|
1169
|
+
var isOAuthTokenResponse = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1170
|
+
var formatOAuthTokenResponseMessage = (fieldLabel, providerLabel = "OAuth provider", operation = "token response") => `${providerLabel} OAuth ${operation} did not return ${fieldLabel}.`;
|
|
1171
|
+
var getOAuthExpiresAtFromExpiresIn = (expiresIn, options = {}) => {
|
|
1172
|
+
let {
|
|
1173
|
+
nowMs = Date.now(),
|
|
1174
|
+
providerLabel,
|
|
1175
|
+
operation,
|
|
1176
|
+
required = false,
|
|
1177
|
+
expiresInType = "numberLike",
|
|
1178
|
+
message
|
|
1179
|
+
} = options;
|
|
1180
|
+
if (expiresIn === void 0 || expiresIn === null || expiresIn === "") {
|
|
1181
|
+
if (required) {
|
|
1182
|
+
throw createApiServiceError(
|
|
1183
|
+
message ?? formatOAuthTokenResponseMessage(
|
|
1184
|
+
"a valid expires_in value",
|
|
1185
|
+
providerLabel,
|
|
1186
|
+
operation
|
|
1187
|
+
),
|
|
1188
|
+
{ reason: "oauth_token_response" }
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
return void 0;
|
|
1192
|
+
}
|
|
1193
|
+
let seconds = typeof expiresIn === "number" ? expiresIn : expiresInType === "numberLike" && typeof expiresIn === "string" ? Number(expiresIn) : Number.NaN;
|
|
1194
|
+
if (!Number.isFinite(seconds)) {
|
|
1195
|
+
throw createApiServiceError(
|
|
1196
|
+
message ?? formatOAuthTokenResponseMessage("a valid expires_in value", providerLabel, operation),
|
|
1197
|
+
{ reason: "oauth_token_response" }
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
return new Date(nowMs + seconds * 1e3).toISOString();
|
|
1201
|
+
};
|
|
1202
|
+
var getRefreshToken = (refreshToken, previousRefreshToken, fallbackMode) => {
|
|
1203
|
+
if (typeof refreshToken === "string") {
|
|
1204
|
+
if (fallbackMode === "falsy" && !refreshToken) {
|
|
1205
|
+
return previousRefreshToken;
|
|
1206
|
+
}
|
|
1207
|
+
return refreshToken;
|
|
1208
|
+
}
|
|
1209
|
+
if (fallbackMode === "falsy" && !refreshToken) {
|
|
1210
|
+
return previousRefreshToken;
|
|
1211
|
+
}
|
|
1212
|
+
return refreshToken === void 0 || refreshToken === null ? previousRefreshToken : void 0;
|
|
1213
|
+
};
|
|
1214
|
+
var normalizeOAuthTokenResponse = (data, options = {}) => {
|
|
1215
|
+
let {
|
|
1216
|
+
providerLabel,
|
|
1217
|
+
operation,
|
|
1218
|
+
previousRefreshToken,
|
|
1219
|
+
refreshTokenFallbackMode = "nullish",
|
|
1220
|
+
accessTokenMessage,
|
|
1221
|
+
expiresInMessage,
|
|
1222
|
+
...expiresAtOptions
|
|
1223
|
+
} = options;
|
|
1224
|
+
if (!isOAuthTokenResponse(data)) {
|
|
1225
|
+
throw createApiServiceError(
|
|
1226
|
+
accessTokenMessage ?? formatOAuthTokenResponseMessage("a token response object", providerLabel, operation),
|
|
1227
|
+
{ reason: "oauth_token_response" }
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
if (typeof data.access_token !== "string" || !data.access_token) {
|
|
1231
|
+
throw createApiServiceError(
|
|
1232
|
+
accessTokenMessage ?? formatOAuthTokenResponseMessage("an access token", providerLabel, operation),
|
|
1233
|
+
{ reason: "oauth_token_response" }
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
return {
|
|
1237
|
+
token: data.access_token,
|
|
1238
|
+
refreshToken: getRefreshToken(
|
|
1239
|
+
data.refresh_token,
|
|
1240
|
+
previousRefreshToken,
|
|
1241
|
+
refreshTokenFallbackMode
|
|
1242
|
+
),
|
|
1243
|
+
expiresAt: getOAuthExpiresAtFromExpiresIn(data.expires_in, {
|
|
1244
|
+
...expiresAtOptions,
|
|
1245
|
+
providerLabel,
|
|
1246
|
+
operation,
|
|
1247
|
+
message: expiresInMessage
|
|
1248
|
+
})
|
|
1249
|
+
};
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1003
1252
|
// src/axios/index.ts
|
|
1004
1253
|
var import_axios3 = __toESM(require("axios"), 1);
|
|
1005
1254
|
|
|
@@ -1583,6 +1832,35 @@ var createAxios = (config2) => {
|
|
|
1583
1832
|
applySlateInterceptors(instance, errorMapping);
|
|
1584
1833
|
return instance;
|
|
1585
1834
|
};
|
|
1835
|
+
var createAuthenticatedAxios = (config2) => {
|
|
1836
|
+
let { authHeader, contentType = "application/json", errorAdapter, ...axiosConfig } = config2;
|
|
1837
|
+
let instance = createAxios({
|
|
1838
|
+
...axiosConfig,
|
|
1839
|
+
headers: {
|
|
1840
|
+
...contentType === false ? {} : { "Content-Type": contentType },
|
|
1841
|
+
...authHeader ? { [authHeader.name ?? "Authorization"]: authHeader.value } : {},
|
|
1842
|
+
...axiosConfig.headers
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
if (errorAdapter) {
|
|
1846
|
+
instance.interceptors.response.use(
|
|
1847
|
+
(response) => response,
|
|
1848
|
+
(error) => Promise.reject(errorAdapter(error))
|
|
1849
|
+
);
|
|
1850
|
+
}
|
|
1851
|
+
return instance;
|
|
1852
|
+
};
|
|
1853
|
+
var requestAxios = async (operation, request, errorAdapter) => {
|
|
1854
|
+
try {
|
|
1855
|
+
return await request();
|
|
1856
|
+
} catch (error) {
|
|
1857
|
+
throw errorAdapter(error, operation);
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
var requestAxiosData = async (operation, request, errorAdapter) => {
|
|
1861
|
+
let response = await requestAxios(operation, request, errorAdapter);
|
|
1862
|
+
return response.data;
|
|
1863
|
+
};
|
|
1586
1864
|
var axios = createAxios();
|
|
1587
1865
|
|
|
1588
1866
|
// src/config/config.ts
|
|
@@ -1661,6 +1939,11 @@ var SlateContext = class {
|
|
|
1661
1939
|
get request() {
|
|
1662
1940
|
return Object.freeze(this.#input.request);
|
|
1663
1941
|
}
|
|
1942
|
+
get registrationDetails() {
|
|
1943
|
+
return Object.freeze(
|
|
1944
|
+
this.#input.registrationDetails
|
|
1945
|
+
);
|
|
1946
|
+
}
|
|
1664
1947
|
get auth() {
|
|
1665
1948
|
return Object.freeze(this.#auth);
|
|
1666
1949
|
}
|
|
@@ -1699,6 +1982,45 @@ var SlateContext = class {
|
|
|
1699
1982
|
}
|
|
1700
1983
|
};
|
|
1701
1984
|
|
|
1985
|
+
// src/crypto/hmac.ts
|
|
1986
|
+
var import_crypto = require("crypto");
|
|
1987
|
+
var createHmacSignature = ({
|
|
1988
|
+
secret,
|
|
1989
|
+
payload,
|
|
1990
|
+
algorithm = "sha256",
|
|
1991
|
+
digest,
|
|
1992
|
+
prefix = ""
|
|
1993
|
+
}) => `${prefix}${(0, import_crypto.createHmac)(algorithm, secret).update(payload).digest(digest)}`;
|
|
1994
|
+
var verifyHmacSignature = (options) => {
|
|
1995
|
+
let expected = createHmacSignature(options);
|
|
1996
|
+
let expectedBytes = Buffer.from(expected);
|
|
1997
|
+
let signatureBytes = Buffer.from(options.signature);
|
|
1998
|
+
let lengthsMatch = signatureBytes.length === expectedBytes.length;
|
|
1999
|
+
let comparableSignature = lengthsMatch ? signatureBytes : Buffer.alloc(expectedBytes.length);
|
|
2000
|
+
return (0, import_crypto.timingSafeEqual)(comparableSignature, expectedBytes) && lengthsMatch;
|
|
2001
|
+
};
|
|
2002
|
+
|
|
2003
|
+
// src/file/index.ts
|
|
2004
|
+
var getResponseHeaderValue = (headers, name) => {
|
|
2005
|
+
if (!headers) return void 0;
|
|
2006
|
+
if (typeof headers.get === "function") {
|
|
2007
|
+
let value = headers.get(name);
|
|
2008
|
+
return typeof value === "string" ? value : void 0;
|
|
2009
|
+
}
|
|
2010
|
+
if (typeof headers !== "object") return void 0;
|
|
2011
|
+
let lowerName = name.toLowerCase();
|
|
2012
|
+
for (let [headerName, value] of Object.entries(headers)) {
|
|
2013
|
+
if (headerName.toLowerCase() !== lowerName) continue;
|
|
2014
|
+
if (Array.isArray(value)) {
|
|
2015
|
+
let first = value.find((item) => typeof item === "string");
|
|
2016
|
+
return typeof first === "string" ? first : void 0;
|
|
2017
|
+
}
|
|
2018
|
+
return typeof value === "string" ? value : void 0;
|
|
2019
|
+
}
|
|
2020
|
+
return void 0;
|
|
2021
|
+
};
|
|
2022
|
+
var getBase64ByteLength = (contentBase64) => Buffer.from(contentBase64, "base64").byteLength;
|
|
2023
|
+
|
|
1702
2024
|
// src/logger/logger.ts
|
|
1703
2025
|
var import_toon = require("@toon-format/toon");
|
|
1704
2026
|
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1794,6 +2116,17 @@ var SlateLogger = class {
|
|
|
1794
2116
|
}
|
|
1795
2117
|
};
|
|
1796
2118
|
|
|
2119
|
+
// src/object/index.ts
|
|
2120
|
+
var pickDefined = (value) => Object.fromEntries(
|
|
2121
|
+
Object.entries(value).filter(([, child]) => child !== void 0)
|
|
2122
|
+
);
|
|
2123
|
+
var setIfDefined = (target, key, value) => {
|
|
2124
|
+
if (value !== void 0) {
|
|
2125
|
+
target[key] = value;
|
|
2126
|
+
}
|
|
2127
|
+
return target;
|
|
2128
|
+
};
|
|
2129
|
+
|
|
1797
2130
|
// src/specification/slate.ts
|
|
1798
2131
|
var Slate = class _Slate {
|
|
1799
2132
|
constructor(_spec, _actions) {
|
|
@@ -1856,6 +2189,59 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
1856
2189
|
}
|
|
1857
2190
|
};
|
|
1858
2191
|
var spec = (params) => SlateSpecification.create(params);
|
|
2192
|
+
|
|
2193
|
+
// src/webhook/graph.ts
|
|
2194
|
+
var graphWebhookHttp = {
|
|
2195
|
+
methods: ["POST"],
|
|
2196
|
+
sync: {
|
|
2197
|
+
mode: "match",
|
|
2198
|
+
match: [{ hasQueryParam: "validationToken" }]
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
2201
|
+
var getGraphWebhookValidationResponse = (request) => {
|
|
2202
|
+
let validationToken = new URL(request.url).searchParams.get("validationToken");
|
|
2203
|
+
if (validationToken === null) return null;
|
|
2204
|
+
return {
|
|
2205
|
+
status: 200,
|
|
2206
|
+
headers: { "content-type": "text/plain" },
|
|
2207
|
+
body: validationToken
|
|
2208
|
+
};
|
|
2209
|
+
};
|
|
2210
|
+
|
|
2211
|
+
// src/webhook/meta.ts
|
|
2212
|
+
var metaWebhookHttp = {
|
|
2213
|
+
methods: ["GET", "POST"],
|
|
2214
|
+
sync: {
|
|
2215
|
+
mode: "match",
|
|
2216
|
+
match: [{ method: "GET", hasQueryParam: "hub.mode" }]
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
|
|
2220
|
+
if (request.method !== "GET") return null;
|
|
2221
|
+
let url = new URL(request.url);
|
|
2222
|
+
let mode = url.searchParams.get("hub.mode");
|
|
2223
|
+
let verifyToken = url.searchParams.get("hub.verify_token");
|
|
2224
|
+
let challenge = url.searchParams.get("hub.challenge");
|
|
2225
|
+
if (mode !== "subscribe" || challenge === null) {
|
|
2226
|
+
return {
|
|
2227
|
+
status: 400,
|
|
2228
|
+
headers: { "content-type": "text/plain" },
|
|
2229
|
+
body: "invalid webhook verification request"
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
if (expectedVerifyToken !== void 0 && verifyToken !== expectedVerifyToken) {
|
|
2233
|
+
return {
|
|
2234
|
+
status: 403,
|
|
2235
|
+
headers: { "content-type": "text/plain" },
|
|
2236
|
+
body: "invalid verify token"
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
return {
|
|
2240
|
+
status: 200,
|
|
2241
|
+
headers: { "content-type": "text/plain" },
|
|
2242
|
+
body: challenge
|
|
2243
|
+
};
|
|
2244
|
+
};
|
|
1859
2245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1860
2246
|
0 && (module.exports = {
|
|
1861
2247
|
Slate,
|
|
@@ -1874,24 +2260,47 @@ var spec = (params) => SlateSpecification.create(params);
|
|
|
1874
2260
|
anyOf,
|
|
1875
2261
|
auth,
|
|
1876
2262
|
axios,
|
|
2263
|
+
buildApiServiceError,
|
|
2264
|
+
collectApiErrorDetails,
|
|
1877
2265
|
config,
|
|
2266
|
+
createApiServiceError,
|
|
2267
|
+
createAuthenticatedAxios,
|
|
1878
2268
|
createAxios,
|
|
1879
2269
|
createBase64Attachment,
|
|
2270
|
+
createHmacSignature,
|
|
1880
2271
|
createSlateError,
|
|
1881
2272
|
createTextAttachment,
|
|
1882
2273
|
createUrlAttachment,
|
|
2274
|
+
extractApiErrorMessage,
|
|
2275
|
+
getApiErrorResponse,
|
|
2276
|
+
getApiErrorStatus,
|
|
2277
|
+
getBase64ByteLength,
|
|
1883
2278
|
getCurrentContext,
|
|
2279
|
+
getGraphWebhookValidationResponse,
|
|
2280
|
+
getMetaWebhookVerificationResponse,
|
|
2281
|
+
getOAuthExpiresAtFromExpiresIn,
|
|
2282
|
+
getResponseHeaderValue,
|
|
1884
2283
|
getServiceErrorData,
|
|
2284
|
+
graphWebhookHttp,
|
|
1885
2285
|
inferSlateErrorFromAxios,
|
|
2286
|
+
isApiErrorRecord,
|
|
1886
2287
|
isAxiosErrorLike,
|
|
1887
2288
|
isServiceErrorData,
|
|
1888
2289
|
mapServiceErrorCode,
|
|
1889
2290
|
mapServiceErrorToSlateErrorInput,
|
|
1890
2291
|
mergeScopes,
|
|
2292
|
+
metaWebhookHttp,
|
|
2293
|
+
normalizeOAuthTokenResponse,
|
|
2294
|
+
pickDefined,
|
|
2295
|
+
requestAxios,
|
|
2296
|
+
requestAxiosData,
|
|
1891
2297
|
runWithContext,
|
|
1892
2298
|
scopeClause,
|
|
2299
|
+
setIfDefined,
|
|
1893
2300
|
spec,
|
|
2301
|
+
statusLabelForApiError,
|
|
1894
2302
|
tool,
|
|
1895
2303
|
trigger,
|
|
1896
|
-
validateScopes
|
|
2304
|
+
validateScopes,
|
|
2305
|
+
verifyHmacSignature
|
|
1897
2306
|
});
|