mitra-interactions-sdk 1.0.66 → 1.0.67
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/README.md +8 -0
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -767,3 +767,11 @@ try {
|
|
|
767
767
|
## Licença
|
|
768
768
|
|
|
769
769
|
MIT
|
|
770
|
+
|
|
771
|
+
### Dentro de uma Server Function (prova de execução)
|
|
772
|
+
|
|
773
|
+
Quando o código roda dentro de uma Server Function, o sandbox recebe a variável de ambiente
|
|
774
|
+
`MITRA_SF_EXECUTION_TOKEN`. A partir da 1.0.67 a SDK a lê sozinha e envia o header
|
|
775
|
+
`X-SF-Execution-Token` em toda chamada ao backend principal. É esse header que libera
|
|
776
|
+
`getFileLinkMitra`, `downloadFilePrivateMitra`, `deleteFileMitra` e `uploadFilePrivateMitra` para
|
|
777
|
+
a SF, mesmo quando quem disparou a SF é um usuário final (business). No navegador nada muda.
|
package/dist/index.d.mts
CHANGED
|
@@ -1408,4 +1408,27 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
|
|
|
1408
1408
|
*/
|
|
1409
1409
|
declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
|
|
1410
1410
|
|
|
1411
|
-
|
|
1411
|
+
/**
|
|
1412
|
+
* Prova de execução de Server Function (TKT-ecc38de6 / TKT-000a0394).
|
|
1413
|
+
*
|
|
1414
|
+
* O contrato de anexos privados manda a tela de usuário final pedir o arquivo a uma Server
|
|
1415
|
+
* Function, que valida o registro dono e só então pede o link/download ao backend. O backend
|
|
1416
|
+
* libera o acesso por chave quando a requisição traz o header `X-SF-Execution-Token` — um token
|
|
1417
|
+
* assinado que SÓ o sandbox da execução recebe, como variável de ambiente
|
|
1418
|
+
* `MITRA_SF_EXECUTION_TOKEN`. Até aqui nenhuma SDK repassava esse token, então o caminho não
|
|
1419
|
+
* funcionava e quem precisava de tela com anexo caía no upload público.
|
|
1420
|
+
*
|
|
1421
|
+
* Regras:
|
|
1422
|
+
* - só em Node (sem `window`): no navegador a variável não existe e o header nunca deve sair;
|
|
1423
|
+
* - só quando a variável está preenchida; vazio/ausente = nada muda;
|
|
1424
|
+
* - só para o backend principal (baseURL). O serviço de integrações não recebe a prova.
|
|
1425
|
+
*/
|
|
1426
|
+
declare const SF_EXECUTION_TOKEN_ENV = "MITRA_SF_EXECUTION_TOKEN";
|
|
1427
|
+
declare const SF_EXECUTION_TOKEN_HEADER = "X-SF-Execution-Token";
|
|
1428
|
+
type EnvLike = Record<string, string | undefined> | undefined;
|
|
1429
|
+
/**
|
|
1430
|
+
* Token de prova da execução corrente, ou null quando não estamos dentro de uma Server Function.
|
|
1431
|
+
*/
|
|
1432
|
+
declare function readServerFunctionProof(env?: EnvLike, hasWindow?: boolean): string | null;
|
|
1433
|
+
|
|
1434
|
+
export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteFileOptions, type DeleteFileResponse, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type DownloadFileOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type FileLinkOptions, type FileLinkResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, SF_EXECUTION_TOKEN_ENV, SF_EXECUTION_TOKEN_HEADER, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, closeChatMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteFileMitra, deleteProfileMitra, deleteRecordMitra, downloadFilePrivateMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getFileLinkMitra, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, readServerFunctionProof, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePrivateMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
|
package/dist/index.d.ts
CHANGED
|
@@ -1408,4 +1408,27 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
|
|
|
1408
1408
|
*/
|
|
1409
1409
|
declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
|
|
1410
1410
|
|
|
1411
|
-
|
|
1411
|
+
/**
|
|
1412
|
+
* Prova de execução de Server Function (TKT-ecc38de6 / TKT-000a0394).
|
|
1413
|
+
*
|
|
1414
|
+
* O contrato de anexos privados manda a tela de usuário final pedir o arquivo a uma Server
|
|
1415
|
+
* Function, que valida o registro dono e só então pede o link/download ao backend. O backend
|
|
1416
|
+
* libera o acesso por chave quando a requisição traz o header `X-SF-Execution-Token` — um token
|
|
1417
|
+
* assinado que SÓ o sandbox da execução recebe, como variável de ambiente
|
|
1418
|
+
* `MITRA_SF_EXECUTION_TOKEN`. Até aqui nenhuma SDK repassava esse token, então o caminho não
|
|
1419
|
+
* funcionava e quem precisava de tela com anexo caía no upload público.
|
|
1420
|
+
*
|
|
1421
|
+
* Regras:
|
|
1422
|
+
* - só em Node (sem `window`): no navegador a variável não existe e o header nunca deve sair;
|
|
1423
|
+
* - só quando a variável está preenchida; vazio/ausente = nada muda;
|
|
1424
|
+
* - só para o backend principal (baseURL). O serviço de integrações não recebe a prova.
|
|
1425
|
+
*/
|
|
1426
|
+
declare const SF_EXECUTION_TOKEN_ENV = "MITRA_SF_EXECUTION_TOKEN";
|
|
1427
|
+
declare const SF_EXECUTION_TOKEN_HEADER = "X-SF-Execution-Token";
|
|
1428
|
+
type EnvLike = Record<string, string | undefined> | undefined;
|
|
1429
|
+
/**
|
|
1430
|
+
* Token de prova da execução corrente, ou null quando não estamos dentro de uma Server Function.
|
|
1431
|
+
*/
|
|
1432
|
+
declare function readServerFunctionProof(env?: EnvLike, hasWindow?: boolean): string | null;
|
|
1433
|
+
|
|
1434
|
+
export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteFileOptions, type DeleteFileResponse, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type DownloadFileOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type FileLinkOptions, type FileLinkResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, SF_EXECUTION_TOKEN_ENV, SF_EXECUTION_TOKEN_HEADER, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, closeChatMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteFileMitra, deleteProfileMitra, deleteRecordMitra, downloadFilePrivateMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getFileLinkMitra, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, readServerFunctionProof, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePrivateMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
|
package/dist/index.js
CHANGED
|
@@ -361,6 +361,28 @@ async function resetPasswordMitra(options) {
|
|
|
361
361
|
});
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
// src/sf-proof.ts
|
|
365
|
+
var SF_EXECUTION_TOKEN_ENV = "MITRA_SF_EXECUTION_TOKEN";
|
|
366
|
+
var SF_EXECUTION_TOKEN_HEADER = "X-SF-Execution-Token";
|
|
367
|
+
function defaultEnv() {
|
|
368
|
+
const proc = globalThis.process;
|
|
369
|
+
return proc == null ? void 0 : proc.env;
|
|
370
|
+
}
|
|
371
|
+
function defaultHasWindow() {
|
|
372
|
+
return typeof globalThis.window !== "undefined";
|
|
373
|
+
}
|
|
374
|
+
function readServerFunctionProof(env = defaultEnv(), hasWindow = defaultHasWindow()) {
|
|
375
|
+
if (hasWindow) return null;
|
|
376
|
+
const raw = env == null ? void 0 : env[SF_EXECUTION_TOKEN_ENV];
|
|
377
|
+
if (typeof raw !== "string") return null;
|
|
378
|
+
const token = raw.trim();
|
|
379
|
+
return token.length > 0 ? token : null;
|
|
380
|
+
}
|
|
381
|
+
function withServerFunctionProof(headers, proof = readServerFunctionProof()) {
|
|
382
|
+
if (!proof) return headers;
|
|
383
|
+
return { ...headers, [SF_EXECUTION_TOKEN_HEADER]: proof };
|
|
384
|
+
}
|
|
385
|
+
|
|
364
386
|
// src/client.ts
|
|
365
387
|
function getFetch2() {
|
|
366
388
|
if (typeof globalThis.fetch === "function") {
|
|
@@ -375,7 +397,7 @@ function buildHeaders() {
|
|
|
375
397
|
const config = getConfig();
|
|
376
398
|
const headers = { "Content-Type": "application/json" };
|
|
377
399
|
if (config.token) headers["Authorization"] = formatToken(config.token);
|
|
378
|
-
return headers;
|
|
400
|
+
return withServerFunctionProof(headers);
|
|
379
401
|
}
|
|
380
402
|
function buildUrl(endpoint, params) {
|
|
381
403
|
const config = getConfig();
|
|
@@ -483,7 +505,7 @@ var http = {
|
|
|
483
505
|
if (config.token) headers["Authorization"] = formatToken(config.token);
|
|
484
506
|
return fetchWithRefresh(buildUrl(endpoint), {
|
|
485
507
|
method: "POST",
|
|
486
|
-
headers,
|
|
508
|
+
headers: withServerFunctionProof(headers),
|
|
487
509
|
body: formData
|
|
488
510
|
});
|
|
489
511
|
},
|
|
@@ -2310,6 +2332,8 @@ function resolveProjectId2(projectId) {
|
|
|
2310
2332
|
throw new Error("projectId \xE9 obrigat\xF3rio. Passe nas options ou configure via configureSdkMitra({ projectId }).");
|
|
2311
2333
|
}
|
|
2312
2334
|
|
|
2335
|
+
exports.SF_EXECUTION_TOKEN_ENV = SF_EXECUTION_TOKEN_ENV;
|
|
2336
|
+
exports.SF_EXECUTION_TOKEN_HEADER = SF_EXECUTION_TOKEN_HEADER;
|
|
2313
2337
|
exports.callIntegrationMitra = callIntegrationMitra;
|
|
2314
2338
|
exports.closeChatMitra = closeChatMitra;
|
|
2315
2339
|
exports.configureSdkMitra = configureSdkMitra;
|
|
@@ -2350,6 +2374,7 @@ exports.manageAgentChatMitra = manageAgentChatMitra;
|
|
|
2350
2374
|
exports.manageAgentCredentialMitra = manageAgentCredentialMitra;
|
|
2351
2375
|
exports.openChatMitra = openChatMitra;
|
|
2352
2376
|
exports.patchRecordMitra = patchRecordMitra;
|
|
2377
|
+
exports.readServerFunctionProof = readServerFunctionProof;
|
|
2353
2378
|
exports.refreshTokenSilently = refreshTokenSilently;
|
|
2354
2379
|
exports.resetPasswordMitra = resetPasswordMitra;
|
|
2355
2380
|
exports.resolveProjectId = resolveProjectId2;
|