@dainprotocol/service-sdk 2.0.53 → 2.0.55
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 +78 -0
- package/dist/client/client.d.ts +14 -1
- package/dist/client/client.js +21 -2
- package/dist/client/client.js.map +1 -1
- package/dist/client/types.d.ts +38 -0
- package/dist/client/types.js +35 -1
- package/dist/client/types.js.map +1 -1
- package/dist/lib/schemaStructure.d.ts +2 -1
- package/dist/lib/schemaStructure.js +25 -11
- package/dist/lib/schemaStructure.js.map +1 -1
- package/dist/service/actionable-tools.d.ts +135 -0
- package/dist/service/actionable-tools.js +144 -0
- package/dist/service/actionable-tools.js.map +1 -0
- package/dist/service/direct-auth-setup.d.ts +154 -0
- package/dist/service/direct-auth-setup.js +308 -0
- package/dist/service/direct-auth-setup.js.map +1 -0
- package/dist/service/index.d.ts +3 -1
- package/dist/service/index.js +10 -1
- package/dist/service/index.js.map +1 -1
- package/dist/service/nodeService.js +2 -0
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/oauth2.d.ts +40 -1
- package/dist/service/oauth2.js +46 -0
- package/dist/service/oauth2.js.map +1 -1
- package/dist/service/oauth2Manager.d.ts +31 -4
- package/dist/service/oauth2Manager.js +119 -8
- package/dist/service/oauth2Manager.js.map +1 -1
- package/dist/service/server.js +93 -19
- package/dist/service/server.js.map +1 -1
- package/dist/service/service.js +6 -1
- package/dist/service/service.js.map +1 -1
- package/dist/service/types.d.ts +59 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaStructure.js","sourceRoot":"","sources":["../../src/lib/schemaStructure.ts"],"names":[],"mappings":";AAAA,kCAAkC;;
|
|
1
|
+
{"version":3,"file":"schemaStructure.js","sourceRoot":"","sources":["../../src/lib/schemaStructure.ts"],"names":[],"mappings":";AAAA,kCAAkC;;AAQlC,0CAcC;AA0ND,8CA2BC;AAED,gEA0GC;AArXD,6BAAiC;AAEjC;;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AC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAa,EAAE,EAAE,CAClE,0BAA0B,CAAC,IAAI,CAAC,CACjC;aACF,CAAC;QACJ,KAAK,iBAAiB;YACpB,OAAO;gBACL,GAAG,QAAQ;gBACX,IAAI,EAAE,0BAA0B,CAC7B,MAAsC,CAAC,IAAI,CAAC,IAAI,CAClD;gBACD,KAAK,EAAE,0BAA0B,CAC9B,MAAsC,CAAC,IAAI,CAAC,KAAK,CACnD;aACF,CAAC;QACJ,KAAK,uBAAuB,CAAC,CAAC,CAAC;YAK7B,MAAM,KAAK,GAAI,MAA4B,CAAC,IAA6B,CAAC;YAC1E,OAAO;gBACL,GAAG,QAAQ;gBACX,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAC7C,CAAC,MAAe,EAAE,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,CACxD;aACF,CAAC;QACJ,CAAC;QACD,KAAK,YAAY;YACf,OAAO;gBACL,GAAG,QAAQ;gBACX,SAAS,EAAE,0BAA0B,CAClC,MAA4B,CAAC,IAAI,CAAC,SAAS,CAC7C;gBACD,YAAY,EAAG,MAA4B,CAAC,IAAI,CAAC,YAAY;aAC9D,CAAC;QAEJ;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actionable Tool Schema & Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides standardized schema and helpers for tools that send actionable messages.
|
|
5
|
+
* These tools enable users to trigger system actions through responses (buttons, callbacks, links).
|
|
6
|
+
*
|
|
7
|
+
* @see automation-core/src/core/tools/actionable-tool.schema.ts (matching schema)
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { ToolConfig, AgentInfo, ToolContext } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Action button/option schema
|
|
13
|
+
*/
|
|
14
|
+
export declare const ActionSchema: z.ZodObject<{
|
|
15
|
+
label: z.ZodString;
|
|
16
|
+
type: z.ZodEnum<{
|
|
17
|
+
url: "url";
|
|
18
|
+
custom: "custom";
|
|
19
|
+
callback: "callback";
|
|
20
|
+
approve: "approve";
|
|
21
|
+
reject: "reject";
|
|
22
|
+
}>;
|
|
23
|
+
value: z.ZodOptional<z.ZodString>;
|
|
24
|
+
url: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Automation metadata schema (auto-injected by automation-core)
|
|
28
|
+
*/
|
|
29
|
+
export declare const MetadataSchema: z.ZodObject<{
|
|
30
|
+
runId: z.ZodOptional<z.ZodString>;
|
|
31
|
+
waitId: z.ZodOptional<z.ZodString>;
|
|
32
|
+
automationId: z.ZodOptional<z.ZodString>;
|
|
33
|
+
interactionUrl: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
/**
|
|
36
|
+
* Base schema for all actionable tools
|
|
37
|
+
* Tools marked with supportsUserActions: true MUST accept these fields
|
|
38
|
+
*/
|
|
39
|
+
export declare const ActionableToolBaseSchema: z.ZodObject<{
|
|
40
|
+
recipient: z.ZodString;
|
|
41
|
+
message: z.ZodString;
|
|
42
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
43
|
+
label: z.ZodString;
|
|
44
|
+
type: z.ZodEnum<{
|
|
45
|
+
url: "url";
|
|
46
|
+
custom: "custom";
|
|
47
|
+
callback: "callback";
|
|
48
|
+
approve: "approve";
|
|
49
|
+
reject: "reject";
|
|
50
|
+
}>;
|
|
51
|
+
value: z.ZodOptional<z.ZodString>;
|
|
52
|
+
url: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>>>;
|
|
54
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
55
|
+
runId: z.ZodOptional<z.ZodString>;
|
|
56
|
+
waitId: z.ZodOptional<z.ZodString>;
|
|
57
|
+
automationId: z.ZodOptional<z.ZodString>;
|
|
58
|
+
interactionUrl: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strip>>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
/**
|
|
62
|
+
* TypeScript type inferred from schema
|
|
63
|
+
*/
|
|
64
|
+
export type ActionableToolInput = z.infer<typeof ActionableToolBaseSchema>;
|
|
65
|
+
export type Action = z.infer<typeof ActionSchema>;
|
|
66
|
+
export type AutomationMetadata = z.infer<typeof MetadataSchema>;
|
|
67
|
+
/**
|
|
68
|
+
* Extend base actionable schema with tool-specific fields
|
|
69
|
+
* Use this to add additional parameters while keeping the standard actionable fields
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const TelegramInputSchema = extendActionableSchema({
|
|
74
|
+
* parse_mode: z.enum(['HTML', 'Markdown']).optional(),
|
|
75
|
+
* disable_notification: z.boolean().optional(),
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function extendActionableSchema<T extends z.ZodRawShape>(additionalFields: T): z.ZodObject<z.ZodRawShape>;
|
|
80
|
+
/**
|
|
81
|
+
* Helper function to build an actionable tool with type safety and schema enforcement
|
|
82
|
+
* Automatically merges base actionable schema with tool-specific fields
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* export const sendTelegramMessage = buildActionableTool({
|
|
87
|
+
* id: 'send-telegram-message',
|
|
88
|
+
* name: 'Send Telegram Message',
|
|
89
|
+
* description: 'Send a message with interactive buttons to a Telegram chat',
|
|
90
|
+
* additionalFields: {
|
|
91
|
+
* parse_mode: z.enum(['HTML', 'Markdown']).optional(),
|
|
92
|
+
* },
|
|
93
|
+
* handler: async (input, agentInfo, context) => {
|
|
94
|
+
* // input is typed with: recipient, message, actions, metadata, parse_mode
|
|
95
|
+
* const { recipient, message, actions, parse_mode } = input;
|
|
96
|
+
*
|
|
97
|
+
* // Use recipient as chatId for Telegram API
|
|
98
|
+
* const result = await sendToTelegram({
|
|
99
|
+
* chat_id: recipient,
|
|
100
|
+
* text: message,
|
|
101
|
+
* parse_mode,
|
|
102
|
+
* reply_markup: actions ? buildInlineKeyboard(actions) : undefined,
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* return {
|
|
106
|
+
* text: `Message sent to ${recipient}`,
|
|
107
|
+
* data: { messageId: result.message_id },
|
|
108
|
+
* };
|
|
109
|
+
* },
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function buildActionableTool<TAdditional extends z.ZodRawShape = {}, TOutput extends z.ZodType = z.ZodAny>(config: {
|
|
114
|
+
id: string;
|
|
115
|
+
name: string;
|
|
116
|
+
description: string;
|
|
117
|
+
additionalFields?: TAdditional;
|
|
118
|
+
output?: TOutput;
|
|
119
|
+
handler: (input: ActionableToolInput & z.infer<z.ZodObject<TAdditional>>, agentInfo: AgentInfo, context: ToolContext) => Promise<{
|
|
120
|
+
success?: boolean;
|
|
121
|
+
text: string;
|
|
122
|
+
data: z.output<TOutput>;
|
|
123
|
+
ui?: any;
|
|
124
|
+
pleasePay?: any;
|
|
125
|
+
processes?: string[] | any[];
|
|
126
|
+
}>;
|
|
127
|
+
}): ToolConfig;
|
|
128
|
+
/**
|
|
129
|
+
* Validate that a tool schema includes required actionable fields
|
|
130
|
+
* Use this to check if a manually-defined tool complies with actionable schema
|
|
131
|
+
*/
|
|
132
|
+
export declare function validateActionableSchema(toolConfig: ToolConfig): {
|
|
133
|
+
valid: boolean;
|
|
134
|
+
errors?: string[];
|
|
135
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Actionable Tool Schema & Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides standardized schema and helpers for tools that send actionable messages.
|
|
6
|
+
* These tools enable users to trigger system actions through responses (buttons, callbacks, links).
|
|
7
|
+
*
|
|
8
|
+
* @see automation-core/src/core/tools/actionable-tool.schema.ts (matching schema)
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ActionableToolBaseSchema = exports.MetadataSchema = exports.ActionSchema = void 0;
|
|
12
|
+
exports.extendActionableSchema = extendActionableSchema;
|
|
13
|
+
exports.buildActionableTool = buildActionableTool;
|
|
14
|
+
exports.validateActionableSchema = validateActionableSchema;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
/**
|
|
17
|
+
* Action button/option schema
|
|
18
|
+
*/
|
|
19
|
+
exports.ActionSchema = zod_1.z.object({
|
|
20
|
+
label: zod_1.z.string().describe('Button/action label shown to user'),
|
|
21
|
+
type: zod_1.z
|
|
22
|
+
.enum(['approve', 'reject', 'callback', 'url', 'custom'])
|
|
23
|
+
.describe('Type of action'),
|
|
24
|
+
value: zod_1.z.string().optional().describe('Value sent back when action is triggered'),
|
|
25
|
+
url: zod_1.z.string().optional().describe('URL to open (for url type actions)'),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Automation metadata schema (auto-injected by automation-core)
|
|
29
|
+
*/
|
|
30
|
+
exports.MetadataSchema = zod_1.z.object({
|
|
31
|
+
runId: zod_1.z.string().optional().describe('Current run ID'),
|
|
32
|
+
waitId: zod_1.z.string().optional().describe('Wait node ID if applicable'),
|
|
33
|
+
automationId: zod_1.z.string().optional().describe('Automation ID'),
|
|
34
|
+
interactionUrl: zod_1.z.string().optional().describe('URL for user interaction'),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Base schema for all actionable tools
|
|
38
|
+
* Tools marked with supportsUserActions: true MUST accept these fields
|
|
39
|
+
*/
|
|
40
|
+
exports.ActionableToolBaseSchema = zod_1.z.object({
|
|
41
|
+
recipient: zod_1.z.string().describe('Who receives this message (chatId, channel, email, etc.)'),
|
|
42
|
+
message: zod_1.z.string().describe('The message text to send'),
|
|
43
|
+
actions: zod_1.z.array(exports.ActionSchema).optional().describe('Interactive actions the user can trigger'),
|
|
44
|
+
metadata: exports.MetadataSchema.optional().describe('Automation metadata (auto-injected by system)'),
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Extend base actionable schema with tool-specific fields
|
|
48
|
+
* Use this to add additional parameters while keeping the standard actionable fields
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const TelegramInputSchema = extendActionableSchema({
|
|
53
|
+
* parse_mode: z.enum(['HTML', 'Markdown']).optional(),
|
|
54
|
+
* disable_notification: z.boolean().optional(),
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function extendActionableSchema(additionalFields) {
|
|
59
|
+
return exports.ActionableToolBaseSchema.extend(additionalFields);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Helper function to build an actionable tool with type safety and schema enforcement
|
|
63
|
+
* Automatically merges base actionable schema with tool-specific fields
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* export const sendTelegramMessage = buildActionableTool({
|
|
68
|
+
* id: 'send-telegram-message',
|
|
69
|
+
* name: 'Send Telegram Message',
|
|
70
|
+
* description: 'Send a message with interactive buttons to a Telegram chat',
|
|
71
|
+
* additionalFields: {
|
|
72
|
+
* parse_mode: z.enum(['HTML', 'Markdown']).optional(),
|
|
73
|
+
* },
|
|
74
|
+
* handler: async (input, agentInfo, context) => {
|
|
75
|
+
* // input is typed with: recipient, message, actions, metadata, parse_mode
|
|
76
|
+
* const { recipient, message, actions, parse_mode } = input;
|
|
77
|
+
*
|
|
78
|
+
* // Use recipient as chatId for Telegram API
|
|
79
|
+
* const result = await sendToTelegram({
|
|
80
|
+
* chat_id: recipient,
|
|
81
|
+
* text: message,
|
|
82
|
+
* parse_mode,
|
|
83
|
+
* reply_markup: actions ? buildInlineKeyboard(actions) : undefined,
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* return {
|
|
87
|
+
* text: `Message sent to ${recipient}`,
|
|
88
|
+
* data: { messageId: result.message_id },
|
|
89
|
+
* };
|
|
90
|
+
* },
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
function buildActionableTool(config) {
|
|
95
|
+
// Merge base actionable schema with additional fields
|
|
96
|
+
const inputSchema = config.additionalFields
|
|
97
|
+
? exports.ActionableToolBaseSchema.extend(config.additionalFields)
|
|
98
|
+
: exports.ActionableToolBaseSchema;
|
|
99
|
+
const outputSchema = config.output || zod_1.z.any();
|
|
100
|
+
return {
|
|
101
|
+
id: config.id,
|
|
102
|
+
name: config.name,
|
|
103
|
+
description: config.description,
|
|
104
|
+
input: inputSchema,
|
|
105
|
+
output: outputSchema,
|
|
106
|
+
supportsUserActions: true, // Always true for actionable tools
|
|
107
|
+
handler: config.handler,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Validate that a tool schema includes required actionable fields
|
|
112
|
+
* Use this to check if a manually-defined tool complies with actionable schema
|
|
113
|
+
*/
|
|
114
|
+
function validateActionableSchema(toolConfig) {
|
|
115
|
+
if (!toolConfig.supportsUserActions) {
|
|
116
|
+
return { valid: true }; // Not an actionable tool, no validation needed
|
|
117
|
+
}
|
|
118
|
+
const errors = [];
|
|
119
|
+
// Check if input schema is a Zod object
|
|
120
|
+
if (!(toolConfig.input instanceof zod_1.z.ZodObject)) {
|
|
121
|
+
errors.push('Input schema must be a Zod object for actionable tools');
|
|
122
|
+
return { valid: false, errors };
|
|
123
|
+
}
|
|
124
|
+
const shape = toolConfig.input.shape;
|
|
125
|
+
// Check required fields
|
|
126
|
+
if (!shape.recipient) {
|
|
127
|
+
errors.push("Missing required field: 'recipient'");
|
|
128
|
+
}
|
|
129
|
+
if (!shape.message) {
|
|
130
|
+
errors.push("Missing required field: 'message'");
|
|
131
|
+
}
|
|
132
|
+
// Check field types
|
|
133
|
+
if (shape.recipient && !(shape.recipient instanceof zod_1.z.ZodString)) {
|
|
134
|
+
errors.push("Field 'recipient' must be a string");
|
|
135
|
+
}
|
|
136
|
+
if (shape.message && !(shape.message instanceof zod_1.z.ZodString)) {
|
|
137
|
+
errors.push("Field 'message' must be a string");
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
valid: errors.length === 0,
|
|
141
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=actionable-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionable-tools.js","sourceRoot":"","sources":["../../src/service/actionable-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAyDH,wDAIC;AAmCD,kDAsCC;AAMD,4DAsCC;AAhLD,6BAAwB;AAGxB;;GAEG;AACU,QAAA,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IAC/D,IAAI,EAAE,OAAC;SACJ,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;SACxD,QAAQ,CAAC,gBAAgB,CAAC;IAC7B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;IACjF,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;CAC1E,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,g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CAAC,SAAS,CAAC,EAAE,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAClD,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;KAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { StorageAdapter } from '@dainprotocol/oauth2-token-manager';
|
|
2
|
+
/**
|
|
3
|
+
* Pending setup information
|
|
4
|
+
*/
|
|
5
|
+
export interface PendingSetup {
|
|
6
|
+
setupCode: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
expiresAt: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Setup completion result
|
|
13
|
+
*/
|
|
14
|
+
export interface SetupCompletionResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
userId?: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Onboarding UI configuration
|
|
21
|
+
* Returned by adapter to display setup instructions to user
|
|
22
|
+
*/
|
|
23
|
+
export interface OnboardingUI {
|
|
24
|
+
/** Primary action URL (e.g., deep link, authorization URL) */
|
|
25
|
+
actionUrl: string;
|
|
26
|
+
/** QR code image URL */
|
|
27
|
+
qrCodeUrl?: string;
|
|
28
|
+
/** Instructions to display to the user */
|
|
29
|
+
instructions: string[];
|
|
30
|
+
/** Button label for primary action */
|
|
31
|
+
buttonLabel?: string;
|
|
32
|
+
/** Provider logo URL */
|
|
33
|
+
logoUrl?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* DirectAuthAdapter Interface
|
|
37
|
+
*
|
|
38
|
+
* Contract for provider-specific direct authentication adapters.
|
|
39
|
+
* Implementations handle provider-specific UI generation.
|
|
40
|
+
* Webhook parsing is handled by the service's existing infrastructure.
|
|
41
|
+
*/
|
|
42
|
+
export interface DirectAuthAdapter {
|
|
43
|
+
/** Provider name */
|
|
44
|
+
provider: string;
|
|
45
|
+
/**
|
|
46
|
+
* Generate the onboarding UI for the user
|
|
47
|
+
* @param setupCode - The generated setup code
|
|
48
|
+
* @param expiresAt - Timestamp when the setup code expires
|
|
49
|
+
*/
|
|
50
|
+
generateOnboardingUI(setupCode: string, expiresAt: number): OnboardingUI;
|
|
51
|
+
/**
|
|
52
|
+
* Send a confirmation message after successful setup
|
|
53
|
+
* @param config - The stored configuration
|
|
54
|
+
*/
|
|
55
|
+
sendConfirmation?(config: Record<string, any>): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* DirectAuthSetupManager - Manages temporary setup codes for direct authentication providers
|
|
59
|
+
*
|
|
60
|
+
* Used for services that require user-provided configuration without external OAuth flow
|
|
61
|
+
* Examples: Telegram bot (chat ID), SMS (phone number), custom API endpoints
|
|
62
|
+
*
|
|
63
|
+
* Storage Strategy:
|
|
64
|
+
* - Uses StorageAdapter (backed by database from @dainprotocol/oauth2-storage-drizzle)
|
|
65
|
+
* - Pending setups: Stored as tokens with provider `setup_pending_{provider}`
|
|
66
|
+
* - userId field = setup code (for quick lookup)
|
|
67
|
+
* - email field = actual user ID
|
|
68
|
+
* - metadata = { originalUserId, provider, expiresAt }
|
|
69
|
+
* - token.expiresAt = expiry timestamp
|
|
70
|
+
* - Completed setups: Stored as tokens with provider `{provider}`
|
|
71
|
+
* - userId field = user ID
|
|
72
|
+
* - metadata = { chatId, username, firstName, etc. }
|
|
73
|
+
*/
|
|
74
|
+
export declare class DirectAuthSetupManager {
|
|
75
|
+
private storage;
|
|
76
|
+
constructor(storage: StorageAdapter);
|
|
77
|
+
/**
|
|
78
|
+
* Generate a cryptographically secure setup code
|
|
79
|
+
* 32 hex characters (16 bytes entropy)
|
|
80
|
+
*/
|
|
81
|
+
private generateSetupCode;
|
|
82
|
+
/**
|
|
83
|
+
* Get the pending provider name for storage
|
|
84
|
+
*/
|
|
85
|
+
private getPendingProviderName;
|
|
86
|
+
/**
|
|
87
|
+
* Create a pending setup for a user and provider
|
|
88
|
+
*
|
|
89
|
+
* @param userId - The user ID (e.g., smart account ID)
|
|
90
|
+
* @param provider - The provider name (e.g., 'telegram')
|
|
91
|
+
* @param expiryMinutes - How long the setup code is valid (default: 15 minutes)
|
|
92
|
+
* @returns The generated setup code
|
|
93
|
+
*/
|
|
94
|
+
createSetup(userId: string, provider: string, expiryMinutes?: number): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Verify a setup code is valid and not expired
|
|
97
|
+
*
|
|
98
|
+
* @param setupCode - The setup code to verify
|
|
99
|
+
* @param provider - The provider name
|
|
100
|
+
* @returns The pending setup info if valid, null otherwise
|
|
101
|
+
*/
|
|
102
|
+
verifySetup(setupCode: string, provider: string): Promise<PendingSetup | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Complete setup and store the provider configuration
|
|
105
|
+
*
|
|
106
|
+
* @param setupCode - The setup code that was verified
|
|
107
|
+
* @param provider - The provider name
|
|
108
|
+
* @param config - The configuration to store (e.g., { chatId: 123456789 })
|
|
109
|
+
* @returns Result indicating success or failure
|
|
110
|
+
*/
|
|
111
|
+
completeSetup(setupCode: string, provider: string, config: Record<string, any>): Promise<SetupCompletionResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Check if a user has completed setup for a provider
|
|
114
|
+
*
|
|
115
|
+
* @param userId - The user ID
|
|
116
|
+
* @param provider - The provider name
|
|
117
|
+
* @returns True if setup is complete
|
|
118
|
+
*/
|
|
119
|
+
isSetupComplete(userId: string, provider: string): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Get the stored configuration for a user and provider
|
|
122
|
+
*
|
|
123
|
+
* @param userId - The user ID
|
|
124
|
+
* @param provider - The provider name
|
|
125
|
+
* @returns The stored config or null if not found
|
|
126
|
+
*/
|
|
127
|
+
getProviderConfig(userId: string, provider: string): Promise<Record<string, any> | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Delete provider configuration for a user
|
|
130
|
+
* Used when user wants to disconnect/revoke access
|
|
131
|
+
*
|
|
132
|
+
* @param userId - The user ID
|
|
133
|
+
* @param provider - The provider name
|
|
134
|
+
* @returns True if deleted successfully
|
|
135
|
+
*/
|
|
136
|
+
deleteProviderConfig(userId: string, provider: string): Promise<boolean>;
|
|
137
|
+
/**
|
|
138
|
+
* Get pending setup status for a user
|
|
139
|
+
* Useful for showing setup progress in UI
|
|
140
|
+
*
|
|
141
|
+
* @param userId - The user ID
|
|
142
|
+
* @param provider - The provider name
|
|
143
|
+
* @returns Pending setup info if exists, null otherwise
|
|
144
|
+
*/
|
|
145
|
+
getPendingSetup(userId: string, provider: string): Promise<PendingSetup | null>;
|
|
146
|
+
/**
|
|
147
|
+
* Cleanup expired pending setups
|
|
148
|
+
* Should be called periodically to prevent stale data accumulation
|
|
149
|
+
*
|
|
150
|
+
* @param provider - The provider name to clean up
|
|
151
|
+
* @returns Number of expired setups cleaned up
|
|
152
|
+
*/
|
|
153
|
+
cleanupExpiredSetups(provider: string): Promise<number>;
|
|
154
|
+
}
|