moeba-sdk 1.0.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/dist/client.d.ts +57 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +137 -0
- package/dist/client.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +10 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/oauth.d.ts +26 -0
- package/dist/components/oauth.d.ts.map +1 -0
- package/dist/components/oauth.js +53 -0
- package/dist/components/oauth.js.map +1 -0
- package/dist/components/secret.d.ts +15 -0
- package/dist/components/secret.d.ts.map +1 -0
- package/dist/components/secret.js +25 -0
- package/dist/components/secret.js.map +1 -0
- package/dist/components/workflow.d.ts +63 -0
- package/dist/components/workflow.d.ts.map +1 -0
- package/dist/components/workflow.js +118 -0
- package/dist/components/workflow.js.map +1 -0
- package/dist/handler.d.ts +43 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +136 -0
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/response.d.ts +36 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +84 -0
- package/dist/response.js.map +1 -0
- package/dist/security.d.ts +17 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +63 -0
- package/dist/security.js.map +1 -0
- package/dist/types.d.ts +192 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +22 -0
package/dist/handler.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebhookHandler = void 0;
|
|
4
|
+
const security_1 = require("./security");
|
|
5
|
+
const response_1 = require("./response");
|
|
6
|
+
/**
|
|
7
|
+
* Framework-agnostic webhook handler for processing Moeba A2A requests.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const handler = new WebhookHandler({
|
|
11
|
+
* webhookSecret: 'whsec_...',
|
|
12
|
+
* onMessage: async (message, ctx) => ctx.reply(`You said: ${message.text}`),
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // In your framework route:
|
|
16
|
+
* const response = await handler.handle(rawBodyString, headers);
|
|
17
|
+
* res.json(response);
|
|
18
|
+
*/
|
|
19
|
+
class WebhookHandler {
|
|
20
|
+
secret;
|
|
21
|
+
onMessage;
|
|
22
|
+
onAction;
|
|
23
|
+
onPing;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.secret = options.webhookSecret;
|
|
26
|
+
this.onMessage = options.onMessage;
|
|
27
|
+
this.onAction = options.onAction;
|
|
28
|
+
this.onPing = options.onPing;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Process an incoming webhook request.
|
|
32
|
+
*
|
|
33
|
+
* @param rawBody - The raw request body string (must be unparsed for signature verification)
|
|
34
|
+
* @param headers - Request headers (needs x-moeba-signature at minimum)
|
|
35
|
+
* @returns JSON-RPC response object ready to send back
|
|
36
|
+
*/
|
|
37
|
+
async handle(rawBody, headers) {
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(rawBody);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return this.errorResponse('parse_error', -32700, 'Invalid JSON');
|
|
44
|
+
}
|
|
45
|
+
// Verify HMAC signature
|
|
46
|
+
const signature = headers['x-moeba-signature'];
|
|
47
|
+
if (!signature || !(0, security_1.verifySignature)(signature, rawBody, this.secret)) {
|
|
48
|
+
return this.errorResponse(parsed.id || 'unknown', -32001, 'Invalid signature');
|
|
49
|
+
}
|
|
50
|
+
// Build handler context
|
|
51
|
+
const ctx = this.buildContext(parsed, headers);
|
|
52
|
+
try {
|
|
53
|
+
switch (parsed.method) {
|
|
54
|
+
case 'agent.ping':
|
|
55
|
+
return this.handlePing(parsed, ctx);
|
|
56
|
+
case 'agent.message':
|
|
57
|
+
return this.handleMessage(parsed, ctx);
|
|
58
|
+
case 'agent.action':
|
|
59
|
+
return this.handleAction(parsed, ctx);
|
|
60
|
+
default:
|
|
61
|
+
return this.errorResponse(parsed.id, -32601, `Unknown method: ${parsed.method}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return this.errorResponse(parsed.id, -32000, err.message || 'Internal handler error');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async handlePing(request, ctx) {
|
|
69
|
+
if (this.onPing) {
|
|
70
|
+
const result = await this.onPing(ctx);
|
|
71
|
+
return this.normalizeResult(request.id, result ?? { status: 'ok' });
|
|
72
|
+
}
|
|
73
|
+
return { jsonrpc: '2.0', id: request.id, result: { status: 'ok' } };
|
|
74
|
+
}
|
|
75
|
+
async handleMessage(request, ctx) {
|
|
76
|
+
const message = request.params?.message ?? { text: '', attachments: [] };
|
|
77
|
+
const result = await this.onMessage({ text: message.text || '', attachments: message.attachments || [] }, ctx);
|
|
78
|
+
return this.normalizeResult(request.id, result);
|
|
79
|
+
}
|
|
80
|
+
async handleAction(request, ctx) {
|
|
81
|
+
if (!this.onAction) {
|
|
82
|
+
return { jsonrpc: '2.0', id: request.id, result: { message: { text: 'Action received.' } } };
|
|
83
|
+
}
|
|
84
|
+
const action = request.params?.action ?? {};
|
|
85
|
+
const result = await this.onAction(action, ctx);
|
|
86
|
+
return this.normalizeResult(request.id, result);
|
|
87
|
+
}
|
|
88
|
+
buildContext(request, headers) {
|
|
89
|
+
const requestId = request.id;
|
|
90
|
+
return {
|
|
91
|
+
phoneNumber: request.context?.phoneNumber || headers['x-moeba-user'] || '',
|
|
92
|
+
sessionId: request.context?.sessionId,
|
|
93
|
+
connectionId: headers['x-moeba-connection-id'],
|
|
94
|
+
userName: headers['x-moeba-user-name'],
|
|
95
|
+
userRole: headers['x-moeba-user-role'],
|
|
96
|
+
requestId,
|
|
97
|
+
timestamp: request.context?.timestamp || Date.now(),
|
|
98
|
+
reply: (text) => new response_1.ResponseBuilder(requestId, text),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Normalize handler return values:
|
|
103
|
+
* - string → { message: { text } }
|
|
104
|
+
* - ResponseBuilder → .build()
|
|
105
|
+
* - object with .build() → call .build()
|
|
106
|
+
* - plain object → wrap as result
|
|
107
|
+
*/
|
|
108
|
+
normalizeResult(requestId, value) {
|
|
109
|
+
if (value === undefined || value === null) {
|
|
110
|
+
return { jsonrpc: '2.0', id: requestId, result: { message: { text: '' } } };
|
|
111
|
+
}
|
|
112
|
+
// String shorthand
|
|
113
|
+
if (typeof value === 'string') {
|
|
114
|
+
return { jsonrpc: '2.0', id: requestId, result: { message: { text: value } } };
|
|
115
|
+
}
|
|
116
|
+
// ResponseBuilder instance
|
|
117
|
+
if (value instanceof response_1.ResponseBuilder) {
|
|
118
|
+
return value.build();
|
|
119
|
+
}
|
|
120
|
+
// Object with build() method (duck-typed ResponseBuilder)
|
|
121
|
+
if (typeof value.build === 'function') {
|
|
122
|
+
return value.build();
|
|
123
|
+
}
|
|
124
|
+
// Already a full JSON-RPC response
|
|
125
|
+
if (value.jsonrpc === '2.0') {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
// Plain result object — wrap it
|
|
129
|
+
return { jsonrpc: '2.0', id: requestId, result: value };
|
|
130
|
+
}
|
|
131
|
+
errorResponse(id, code, message) {
|
|
132
|
+
return { jsonrpc: '2.0', id, error: { code, message } };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.WebhookHandler = WebhookHandler;
|
|
136
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":";;;AAAA,yCAA6C;AAC7C,y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Client, MoebaApiError } from './client';
|
|
2
|
+
export { WebhookHandler } from './handler';
|
|
3
|
+
export { ResponseBuilder } from './response';
|
|
4
|
+
export { WorkflowBuilder, OAuthConnect, SecretInput } from './components';
|
|
5
|
+
export { verifySignature, signPayload, signUpload } from './security';
|
|
6
|
+
export type { JsonRpcRequest, JsonRpcResponse, RequestContext, HandlerContext, Attachment, MessageResponse, Component, WorkflowComponent, OAuthConnectComponent, SecretInputComponent, WorkflowTemplate, WorkflowStep, WorkflowFieldType, SelectOption, FieldValidation, PhotoConfig, LocationConfig, AgentAction, WorkflowCompletedAction, OAuthCompleteAction, SecretSubmittedAction, MoebaClientOptions, SendMessagePayload, SendResponse, OAuthTokenResponse, WebhookHandlerOptions, IncomingHeaders, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGtE,YAAY,EAEV,cAAc,EACd,eAAe,EAGf,cAAc,EACd,cAAc,EAGd,UAAU,EACV,eAAe,EAGf,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EAGpB,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EAGd,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EAGrB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAGlB,qBAAqB,EACrB,eAAe,GAChB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signUpload = exports.signPayload = exports.verifySignature = exports.SecretInput = exports.OAuthConnect = exports.WorkflowBuilder = exports.ResponseBuilder = exports.WebhookHandler = exports.MoebaApiError = exports.MoebaClient = void 0;
|
|
4
|
+
// Core classes
|
|
5
|
+
var client_1 = require("./client");
|
|
6
|
+
Object.defineProperty(exports, "MoebaClient", { enumerable: true, get: function () { return client_1.MoebaClient; } });
|
|
7
|
+
Object.defineProperty(exports, "MoebaApiError", { enumerable: true, get: function () { return client_1.MoebaApiError; } });
|
|
8
|
+
var handler_1 = require("./handler");
|
|
9
|
+
Object.defineProperty(exports, "WebhookHandler", { enumerable: true, get: function () { return handler_1.WebhookHandler; } });
|
|
10
|
+
var response_1 = require("./response");
|
|
11
|
+
Object.defineProperty(exports, "ResponseBuilder", { enumerable: true, get: function () { return response_1.ResponseBuilder; } });
|
|
12
|
+
// Component builders
|
|
13
|
+
var components_1 = require("./components");
|
|
14
|
+
Object.defineProperty(exports, "WorkflowBuilder", { enumerable: true, get: function () { return components_1.WorkflowBuilder; } });
|
|
15
|
+
Object.defineProperty(exports, "OAuthConnect", { enumerable: true, get: function () { return components_1.OAuthConnect; } });
|
|
16
|
+
Object.defineProperty(exports, "SecretInput", { enumerable: true, get: function () { return components_1.SecretInput; } });
|
|
17
|
+
// Security utilities
|
|
18
|
+
var security_1 = require("./security");
|
|
19
|
+
Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return security_1.verifySignature; } });
|
|
20
|
+
Object.defineProperty(exports, "signPayload", { enumerable: true, get: function () { return security_1.signPayload; } });
|
|
21
|
+
Object.defineProperty(exports, "signUpload", { enumerable: true, get: function () { return security_1.signUpload; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,mCAAsD;AAA7C,qGAAA,WAAW,OAAA;AAAE,uGAAA,aAAa,OAAA;AACnC,qCAA2C;AAAlC,yGAAA,cAAc,OAAA;AACvB,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AAExB,qBAAqB;AACrB,2CAA0E;AAAjE,6GAAA,eAAe,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,yGAAA,WAAW,OAAA;AAEnD,qBAAqB;AACrB,uCAAsE;AAA7D,2GAAA,eAAe,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,sGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { JsonRpcResponse, Component, WorkflowComponent, OAuthConnectComponent, SecretInputComponent } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Fluent builder for constructing JSON-RPC responses.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* new ResponseBuilder('req_123', 'Hello!')
|
|
7
|
+
* .withWorkflow(workflow)
|
|
8
|
+
* .escalateToOperator()
|
|
9
|
+
* .build()
|
|
10
|
+
*/
|
|
11
|
+
export declare class ResponseBuilder {
|
|
12
|
+
private _requestId;
|
|
13
|
+
private _text;
|
|
14
|
+
private _components;
|
|
15
|
+
private _secretRef?;
|
|
16
|
+
private _escalate;
|
|
17
|
+
private _approvalRequired;
|
|
18
|
+
constructor(requestId: string, text: string);
|
|
19
|
+
/** Attach a workflow component. */
|
|
20
|
+
withWorkflow(workflow: WorkflowComponent): this;
|
|
21
|
+
/** Attach an OAuth connect component. */
|
|
22
|
+
withOAuthConnect(oauth: OAuthConnectComponent): this;
|
|
23
|
+
/** Attach a secret input component. */
|
|
24
|
+
withSecretInput(secret: SecretInputComponent): this;
|
|
25
|
+
/** Attach any component. */
|
|
26
|
+
withComponent(component: Component): this;
|
|
27
|
+
/** Set a secret reference in the response (after storing a user-submitted secret). */
|
|
28
|
+
secretRef(ref: string): this;
|
|
29
|
+
/** Signal that this conversation should be escalated to a human operator. */
|
|
30
|
+
escalateToOperator(): this;
|
|
31
|
+
/** Signal that this response requires operator approval before delivery. */
|
|
32
|
+
operatorApprovalRequired(): this;
|
|
33
|
+
/** Build the final JSON-RPC response object. */
|
|
34
|
+
build(): JsonRpcResponse;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAK3C,mCAAmC;IACnC,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAK/C,yCAAyC;IACzC,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI;IAKpD,uCAAuC;IACvC,eAAe,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAKnD,4BAA4B;IAC5B,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAKzC,sFAAsF;IACtF,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK5B,6EAA6E;IAC7E,kBAAkB,IAAI,IAAI;IAK1B,4EAA4E;IAC5E,wBAAwB,IAAI,IAAI;IAKhC,gDAAgD;IAChD,KAAK,IAAI,eAAe;CAwBzB"}
|
package/dist/response.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseBuilder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Fluent builder for constructing JSON-RPC responses.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* new ResponseBuilder('req_123', 'Hello!')
|
|
9
|
+
* .withWorkflow(workflow)
|
|
10
|
+
* .escalateToOperator()
|
|
11
|
+
* .build()
|
|
12
|
+
*/
|
|
13
|
+
class ResponseBuilder {
|
|
14
|
+
_requestId;
|
|
15
|
+
_text;
|
|
16
|
+
_components = [];
|
|
17
|
+
_secretRef;
|
|
18
|
+
_escalate = false;
|
|
19
|
+
_approvalRequired = false;
|
|
20
|
+
constructor(requestId, text) {
|
|
21
|
+
this._requestId = requestId;
|
|
22
|
+
this._text = text;
|
|
23
|
+
}
|
|
24
|
+
/** Attach a workflow component. */
|
|
25
|
+
withWorkflow(workflow) {
|
|
26
|
+
this._components.push(workflow);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/** Attach an OAuth connect component. */
|
|
30
|
+
withOAuthConnect(oauth) {
|
|
31
|
+
this._components.push(oauth);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/** Attach a secret input component. */
|
|
35
|
+
withSecretInput(secret) {
|
|
36
|
+
this._components.push(secret);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/** Attach any component. */
|
|
40
|
+
withComponent(component) {
|
|
41
|
+
this._components.push(component);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/** Set a secret reference in the response (after storing a user-submitted secret). */
|
|
45
|
+
secretRef(ref) {
|
|
46
|
+
this._secretRef = ref;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/** Signal that this conversation should be escalated to a human operator. */
|
|
50
|
+
escalateToOperator() {
|
|
51
|
+
this._escalate = true;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/** Signal that this response requires operator approval before delivery. */
|
|
55
|
+
operatorApprovalRequired() {
|
|
56
|
+
this._approvalRequired = true;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/** Build the final JSON-RPC response object. */
|
|
60
|
+
build() {
|
|
61
|
+
const result = {
|
|
62
|
+
message: {
|
|
63
|
+
text: this._text,
|
|
64
|
+
...(this._components.length > 0 ? { components: this._components } : {}),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
if (this._secretRef) {
|
|
68
|
+
result.secretRef = this._secretRef;
|
|
69
|
+
}
|
|
70
|
+
if (this._escalate) {
|
|
71
|
+
result.escalateToOperator = true;
|
|
72
|
+
}
|
|
73
|
+
if (this._approvalRequired) {
|
|
74
|
+
result.operatorApprovalRequired = true;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
jsonrpc: '2.0',
|
|
78
|
+
id: this._requestId,
|
|
79
|
+
result,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ResponseBuilder = ResponseBuilder;
|
|
84
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":";;;AAQA;;;;;;;;GAQG;AACH,MAAa,eAAe;IAClB,UAAU,CAAS;IACnB,KAAK,CAAS;IACd,WAAW,GAAgB,EAAE,CAAC;IAC9B,UAAU,CAAU;IACpB,SAAS,GAAG,KAAK,CAAC;IAClB,iBAAiB,GAAG,KAAK,CAAC;IAElC,YAAY,SAAiB,EAAE,IAAY;QACzC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,mCAAmC;IACnC,YAAY,CAAC,QAA2B;Q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AAC,SAAS,EAAE,CAAC;YACnB,MAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,MAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC;QAC1C,CAAC;QAED,OAAO;YACL,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,CAAC,UAAU;YACnB,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AAhFD,0CAgFC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify an incoming HMAC signature from Moeba.
|
|
3
|
+
* Parses `t={timestamp},v1={hmac}`, checks 5-minute replay window,
|
|
4
|
+
* and performs timing-safe comparison.
|
|
5
|
+
*/
|
|
6
|
+
export declare function verifySignature(header: string, body: string, secret: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Sign an outbound JSON payload (e.g. for OAuth refresh requests).
|
|
9
|
+
* Returns header value: `t={timestamp},v1={hmac}`
|
|
10
|
+
*/
|
|
11
|
+
export declare function signPayload(payload: object, secret: string, timestamp?: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Sign a file upload request using phone number (multipart/form-data).
|
|
14
|
+
* Returns header value: `t={timestamp},v1={hmac}`
|
|
15
|
+
*/
|
|
16
|
+
export declare function signUpload(phoneNumber: string, secret: string, timestamp?: number): string;
|
|
17
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAuBT;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAmB,GAC7B,MAAM,CAQR;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAmB,GAC7B,MAAM,CAQR"}
|
package/dist/security.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.verifySignature = verifySignature;
|
|
7
|
+
exports.signPayload = signPayload;
|
|
8
|
+
exports.signUpload = signUpload;
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const REPLAY_WINDOW_MS = 5 * 60 * 1000; // 5 minutes
|
|
11
|
+
/**
|
|
12
|
+
* Verify an incoming HMAC signature from Moeba.
|
|
13
|
+
* Parses `t={timestamp},v1={hmac}`, checks 5-minute replay window,
|
|
14
|
+
* and performs timing-safe comparison.
|
|
15
|
+
*/
|
|
16
|
+
function verifySignature(header, body, secret) {
|
|
17
|
+
const [tPart, vPart] = header.split(',');
|
|
18
|
+
if (!tPart || !vPart)
|
|
19
|
+
return false;
|
|
20
|
+
const timestamp = parseInt(tPart.split('=')[1], 10);
|
|
21
|
+
const signature = vPart.split('=')[1];
|
|
22
|
+
if (!timestamp || !signature)
|
|
23
|
+
return false;
|
|
24
|
+
// Replay attack prevention
|
|
25
|
+
if (Math.abs(Date.now() - timestamp) > REPLAY_WINDOW_MS)
|
|
26
|
+
return false;
|
|
27
|
+
// Reconstruct expected signature
|
|
28
|
+
const expected = crypto_1.default
|
|
29
|
+
.createHmac('sha256', secret)
|
|
30
|
+
.update(`${timestamp}.${body}`)
|
|
31
|
+
.digest('hex');
|
|
32
|
+
// Timing-safe comparison
|
|
33
|
+
const source = Buffer.from(signature);
|
|
34
|
+
const comparison = Buffer.from(expected);
|
|
35
|
+
if (source.length !== comparison.length)
|
|
36
|
+
return false;
|
|
37
|
+
return crypto_1.default.timingSafeEqual(source, comparison);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Sign an outbound JSON payload (e.g. for OAuth refresh requests).
|
|
41
|
+
* Returns header value: `t={timestamp},v1={hmac}`
|
|
42
|
+
*/
|
|
43
|
+
function signPayload(payload, secret, timestamp = Date.now()) {
|
|
44
|
+
const data = `${timestamp}.${JSON.stringify(payload)}`;
|
|
45
|
+
const signature = crypto_1.default
|
|
46
|
+
.createHmac('sha256', secret)
|
|
47
|
+
.update(data)
|
|
48
|
+
.digest('hex');
|
|
49
|
+
return `t=${timestamp},v1=${signature}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sign a file upload request using phone number (multipart/form-data).
|
|
53
|
+
* Returns header value: `t={timestamp},v1={hmac}`
|
|
54
|
+
*/
|
|
55
|
+
function signUpload(phoneNumber, secret, timestamp = Date.now()) {
|
|
56
|
+
const data = `${timestamp}.${phoneNumber}`;
|
|
57
|
+
const signature = crypto_1.default
|
|
58
|
+
.createHmac('sha256', secret)
|
|
59
|
+
.update(data)
|
|
60
|
+
.digest('hex');
|
|
61
|
+
return `t=${timestamp},v1=${signature}`;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":";;;;;AASA,0CA2BC;AAMD,kCAYC;AAMD,gCAYC;AAxED,oDAA4B;AAE5B,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAEpD;;;;GAIG;AACH,SAAgB,eAAe,CAC7B,MAAc,EACd,IAAY,EACZ,MAAc;IAEd,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,KAAK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AM,CAAC,KAAK,CAAC,CAAC;IAEjB,OAAO,KAAK,SAAS,OAAO,SAAS,EAAE,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU,CACxB,WAAmB,EACnB,MAAc,EACd,YAAoB,IAAI,CAAC,GAAG,EAAE;IAE9B,MAAM,IAAI,GAAG,GAAG,SAAS,IAAI,WAAW,EAAE,CAAC;IAC3C,MAAM,SAAS,GAAG,gBAAM;SACrB,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;SAC5B,MAAM,CAAC,IAAI,CAAC;SACZ,MAAM,CAAC,KAAK,CAAC,CAAC;IAEjB,OAAO,KAAK,SAAS,OAAO,SAAS,EAAE,CAAC;AAC1C,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export interface JsonRpcRequest {
|
|
2
|
+
jsonrpc: '2.0';
|
|
3
|
+
id: string;
|
|
4
|
+
method: 'agent.ping' | 'agent.message' | 'agent.action';
|
|
5
|
+
params: {
|
|
6
|
+
message?: {
|
|
7
|
+
text: string;
|
|
8
|
+
attachments?: Attachment[];
|
|
9
|
+
};
|
|
10
|
+
action?: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
context: RequestContext;
|
|
13
|
+
}
|
|
14
|
+
export interface JsonRpcResponse {
|
|
15
|
+
jsonrpc: '2.0';
|
|
16
|
+
id: string;
|
|
17
|
+
result?: {
|
|
18
|
+
status?: string;
|
|
19
|
+
message?: MessageResponse;
|
|
20
|
+
secretRef?: string;
|
|
21
|
+
escalateToOperator?: boolean;
|
|
22
|
+
operatorApprovalRequired?: boolean;
|
|
23
|
+
};
|
|
24
|
+
error?: {
|
|
25
|
+
code: number;
|
|
26
|
+
message: string;
|
|
27
|
+
data?: any;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface RequestContext {
|
|
31
|
+
protocolVersion: '4.0';
|
|
32
|
+
timestamp: number;
|
|
33
|
+
phoneNumber: string;
|
|
34
|
+
sessionId?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface HandlerContext {
|
|
37
|
+
phoneNumber: string;
|
|
38
|
+
sessionId?: string;
|
|
39
|
+
connectionId?: string;
|
|
40
|
+
userName?: string;
|
|
41
|
+
userRole?: string;
|
|
42
|
+
requestId: string;
|
|
43
|
+
timestamp: number;
|
|
44
|
+
reply: (text: string) => ResponseBuilder;
|
|
45
|
+
}
|
|
46
|
+
export interface ResponseBuilder {
|
|
47
|
+
withWorkflow(workflow: WorkflowComponent): this;
|
|
48
|
+
withOAuthConnect(oauth: OAuthConnectComponent): this;
|
|
49
|
+
withSecretInput(secret: SecretInputComponent): this;
|
|
50
|
+
secretRef(ref: string): this;
|
|
51
|
+
escalateToOperator(): this;
|
|
52
|
+
operatorApprovalRequired(): this;
|
|
53
|
+
build(): JsonRpcResponse;
|
|
54
|
+
}
|
|
55
|
+
export interface Attachment {
|
|
56
|
+
type: 'image' | 'file' | 'location';
|
|
57
|
+
uri?: string;
|
|
58
|
+
url?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
mimeType?: string;
|
|
61
|
+
latitude?: number;
|
|
62
|
+
longitude?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface MessageResponse {
|
|
65
|
+
text: string;
|
|
66
|
+
components?: Component[];
|
|
67
|
+
data?: any;
|
|
68
|
+
}
|
|
69
|
+
export type Component = WorkflowComponent | OAuthConnectComponent | SecretInputComponent;
|
|
70
|
+
export interface WorkflowComponent {
|
|
71
|
+
type: 'workflow';
|
|
72
|
+
template: WorkflowTemplate;
|
|
73
|
+
}
|
|
74
|
+
export interface OAuthConnectComponent {
|
|
75
|
+
type: 'oauthConnect';
|
|
76
|
+
provider: 'gmail' | 'office365' | 'github';
|
|
77
|
+
label?: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
scopes?: string[];
|
|
80
|
+
}
|
|
81
|
+
export interface SecretInputComponent {
|
|
82
|
+
type: 'secretInput';
|
|
83
|
+
name: string;
|
|
84
|
+
label: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface WorkflowTemplate {
|
|
88
|
+
name: string;
|
|
89
|
+
referencePrefix: string;
|
|
90
|
+
steps: WorkflowStep[];
|
|
91
|
+
}
|
|
92
|
+
export type WorkflowFieldType = 'text' | 'email' | 'phone' | 'number' | 'date' | 'textarea' | 'select' | 'checkbox' | 'photo' | 'location';
|
|
93
|
+
export interface WorkflowStep {
|
|
94
|
+
order: number;
|
|
95
|
+
name: string;
|
|
96
|
+
title: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
type: WorkflowFieldType;
|
|
99
|
+
required?: boolean;
|
|
100
|
+
canSkip: boolean;
|
|
101
|
+
placeholder?: string;
|
|
102
|
+
options?: SelectOption[];
|
|
103
|
+
validation?: FieldValidation;
|
|
104
|
+
photoConfig?: PhotoConfig;
|
|
105
|
+
locationConfig?: LocationConfig;
|
|
106
|
+
}
|
|
107
|
+
export interface SelectOption {
|
|
108
|
+
label: string;
|
|
109
|
+
value: string;
|
|
110
|
+
}
|
|
111
|
+
export interface FieldValidation {
|
|
112
|
+
pattern?: string;
|
|
113
|
+
patternMessage?: string;
|
|
114
|
+
min?: number;
|
|
115
|
+
max?: number;
|
|
116
|
+
minLength?: number;
|
|
117
|
+
maxLength?: number;
|
|
118
|
+
}
|
|
119
|
+
export interface PhotoConfig {
|
|
120
|
+
maxCount: number;
|
|
121
|
+
requireGeoTag: boolean;
|
|
122
|
+
}
|
|
123
|
+
export interface LocationConfig {
|
|
124
|
+
requireHighAccuracy: boolean;
|
|
125
|
+
}
|
|
126
|
+
export interface WorkflowCompletedAction {
|
|
127
|
+
type: 'workflow_completed';
|
|
128
|
+
workflowName: string;
|
|
129
|
+
data: Record<string, any>;
|
|
130
|
+
}
|
|
131
|
+
export interface OAuthCompleteAction {
|
|
132
|
+
actionId: 'oauth_complete';
|
|
133
|
+
data: {
|
|
134
|
+
provider: string;
|
|
135
|
+
businessId: string;
|
|
136
|
+
connectionId: string;
|
|
137
|
+
access_token: string;
|
|
138
|
+
refresh_token?: string;
|
|
139
|
+
expires_in: number;
|
|
140
|
+
scope?: string;
|
|
141
|
+
token_type: string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export interface SecretSubmittedAction {
|
|
145
|
+
actionId: 'secret_submitted';
|
|
146
|
+
connectionId: string;
|
|
147
|
+
data: {
|
|
148
|
+
name: string;
|
|
149
|
+
value: string;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export type AgentAction = WorkflowCompletedAction | OAuthCompleteAction | SecretSubmittedAction | Record<string, any>;
|
|
153
|
+
export interface MoebaClientOptions {
|
|
154
|
+
apiKey: string;
|
|
155
|
+
baseUrl?: string;
|
|
156
|
+
timeout?: number;
|
|
157
|
+
}
|
|
158
|
+
export interface SendMessagePayload {
|
|
159
|
+
text?: string;
|
|
160
|
+
components?: Component[];
|
|
161
|
+
}
|
|
162
|
+
export interface SendResponse {
|
|
163
|
+
success: boolean;
|
|
164
|
+
conversationId: string;
|
|
165
|
+
connectionId: string;
|
|
166
|
+
messageId?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface OAuthTokenResponse {
|
|
169
|
+
access_token: string;
|
|
170
|
+
refresh_token?: string;
|
|
171
|
+
expires_in: number;
|
|
172
|
+
scope?: string;
|
|
173
|
+
token_type: string;
|
|
174
|
+
}
|
|
175
|
+
export interface WebhookHandlerOptions {
|
|
176
|
+
webhookSecret: string;
|
|
177
|
+
onMessage: (message: {
|
|
178
|
+
text: string;
|
|
179
|
+
attachments: Attachment[];
|
|
180
|
+
}, ctx: HandlerContext) => Promise<any>;
|
|
181
|
+
onAction?: (action: AgentAction, ctx: HandlerContext) => Promise<any>;
|
|
182
|
+
onPing?: (ctx: HandlerContext) => Promise<any>;
|
|
183
|
+
}
|
|
184
|
+
export interface IncomingHeaders {
|
|
185
|
+
'x-moeba-signature'?: string;
|
|
186
|
+
'x-moeba-user'?: string;
|
|
187
|
+
'x-moeba-user-name'?: string;
|
|
188
|
+
'x-moeba-user-role'?: string;
|
|
189
|
+
'x-moeba-connection-id'?: string;
|
|
190
|
+
[key: string]: string | undefined;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,YAAY,GAAG,eAAe,GAAG,cAAc,CAAC;IACxD,MAAM,EAAE;QACN,OAAO,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;SAAE,CAAC;QACvD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC9B,CAAC;IACF,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,eAAe,CAAC;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,wBAAwB,CAAC,EAAE,OAAO,CAAC;KACpC,CAAC;IACF,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,GAAG,CAAC;KACZ,CAAC;CACH;AAMD,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,KAAK,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC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AAG,MAAM,GAAG,SAAS,CAAC;CACnC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// JSON-RPC 2.0
|
|
4
|
+
// =============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,eAAe;AACf,gFAAgF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "moeba-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for building Moeba business agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.9.0",
|
|
16
|
+
"@types/node": "^20.0.0"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|