@promptbook/remote-server 0.98.0 → 0.99.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/README.md +4 -0
- package/esm/index.es.js +147 -1
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/config.d.ts +10 -0
- package/esm/typings/src/remote-server/connection-improvements.test.d.ts +1 -0
- package/esm/typings/src/remote-server/utils/connectionProgress.d.ts +72 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +147 -1
- package/umd/index.umd.js.map +1 -1
|
@@ -138,6 +138,9 @@ export declare const SMALL_NUMBER = 0.001;
|
|
|
138
138
|
/**
|
|
139
139
|
* Timeout for the connections in milliseconds
|
|
140
140
|
*
|
|
141
|
+
* Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
|
|
142
|
+
* like Facebook login which may require user interaction and redirects
|
|
143
|
+
*
|
|
141
144
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
142
145
|
*/
|
|
143
146
|
export declare const CONNECTION_TIMEOUT_MS: number;
|
|
@@ -147,6 +150,13 @@ export declare const CONNECTION_TIMEOUT_MS: number;
|
|
|
147
150
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
148
151
|
*/
|
|
149
152
|
export declare const CONNECTION_RETRIES_LIMIT = 5;
|
|
153
|
+
/**
|
|
154
|
+
* Timeout specifically for OAuth authentication flows in milliseconds
|
|
155
|
+
* OAuth flows typically require more time due to user interaction and redirects
|
|
156
|
+
*
|
|
157
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
158
|
+
*/
|
|
159
|
+
export declare const OAUTH_TIMEOUT_MS: number;
|
|
150
160
|
/**
|
|
151
161
|
* Short time interval to prevent race conditions in milliseconds
|
|
152
162
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection progress utilities for better user experience during authentication
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Connection status types for better progress indication
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export type ConnectionStatus = 'connecting' | 'authenticating' | 'connected' | 'disconnected' | 'error' | 'timeout';
|
|
10
|
+
/**
|
|
11
|
+
* Progress callback function type for connection status updates
|
|
12
|
+
*
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
export type ConnectionProgressCallback = (status: ConnectionStatus, message?: string) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Enhanced connection options with progress reporting
|
|
18
|
+
*
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
export interface ConnectionProgressOptions {
|
|
22
|
+
onProgress?: ConnectionProgressCallback;
|
|
23
|
+
enableProgressReporting?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Default progress messages for different connection states
|
|
27
|
+
*
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_PROGRESS_MESSAGES: {
|
|
31
|
+
readonly connecting: "Connecting to Promptbook server...";
|
|
32
|
+
readonly authenticating: "Authenticating with social provider (Facebook, Google, etc.)...";
|
|
33
|
+
readonly connected: "Successfully connected to Promptbook server";
|
|
34
|
+
readonly disconnected: "Disconnected from Promptbook server";
|
|
35
|
+
readonly error: "Connection failed";
|
|
36
|
+
readonly timeout: "Connection timed out - this may happen during social login flows";
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Creates a progress reporter for connection status
|
|
40
|
+
* This can be used by frontend applications to show connection progress
|
|
41
|
+
*
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
export declare function createConnectionProgressReporter(callback?: ConnectionProgressCallback): ConnectionProgressCallback;
|
|
45
|
+
/**
|
|
46
|
+
* Timeout constants with descriptions for different connection types
|
|
47
|
+
*
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
export declare const CONNECTION_TIMEOUTS: {
|
|
51
|
+
/** Standard timeout for regular connections */
|
|
52
|
+
readonly STANDARD: number;
|
|
53
|
+
/** Extended timeout for OAuth flows that require user interaction */
|
|
54
|
+
readonly OAUTH: number;
|
|
55
|
+
/** Short timeout for quick health checks */
|
|
56
|
+
readonly HEALTH_CHECK: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Helper function to get appropriate timeout based on connection type
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
export declare function getConnectionTimeout(type: 'standard' | 'oauth' | 'health_check'): number;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a timeout wrapper with progress reporting
|
|
66
|
+
*
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
export declare function createTimeoutWithProgress(timeoutMs: number, onProgress?: ConnectionProgressCallback): Promise<never>;
|
|
70
|
+
/**
|
|
71
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
72
|
+
*/
|
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.98.0
|
|
18
|
+
* It follows semantic versioning (e.g., `0.98.0`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.99.0-0",
|
|
4
4
|
"description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"module": "./esm/index.es.js",
|
|
96
96
|
"typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
|
|
97
97
|
"peerDependencies": {
|
|
98
|
-
"@promptbook/core": "0.
|
|
98
|
+
"@promptbook/core": "0.99.0-0"
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
101
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.99.0-0';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8076,6 +8076,152 @@
|
|
|
8076
8076
|
response.status(400).send({ error: serializeError(error) });
|
|
8077
8077
|
}
|
|
8078
8078
|
});
|
|
8079
|
+
// OAuth Authentication Endpoints
|
|
8080
|
+
// These endpoints provide social authentication support (Facebook, Google, etc.)
|
|
8081
|
+
app.get('/auth/:provider', async (request, response) => {
|
|
8082
|
+
const { provider } = request.params;
|
|
8083
|
+
if (!isApplicationModeAllowed) {
|
|
8084
|
+
response.status(400).json({
|
|
8085
|
+
error: 'Application mode is not allowed',
|
|
8086
|
+
message: 'Social authentication requires application mode to be enabled'
|
|
8087
|
+
});
|
|
8088
|
+
return;
|
|
8089
|
+
}
|
|
8090
|
+
try {
|
|
8091
|
+
// Get OAuth configuration from query params or environment
|
|
8092
|
+
const { redirectUri, clientId, appId } = request.query;
|
|
8093
|
+
if (!redirectUri || !clientId) {
|
|
8094
|
+
response.status(400).json({
|
|
8095
|
+
error: 'Missing OAuth parameters',
|
|
8096
|
+
message: 'redirectUri and clientId are required for OAuth flow'
|
|
8097
|
+
});
|
|
8098
|
+
return;
|
|
8099
|
+
}
|
|
8100
|
+
let authUrl;
|
|
8101
|
+
const state = Buffer.from(JSON.stringify({
|
|
8102
|
+
appId: appId || 'default',
|
|
8103
|
+
timestamp: Date.now()
|
|
8104
|
+
})).toString('base64');
|
|
8105
|
+
switch (provider.toLowerCase()) {
|
|
8106
|
+
case 'facebook':
|
|
8107
|
+
authUrl = `https://www.facebook.com/v18.0/dialog/oauth?` +
|
|
8108
|
+
`client_id=${encodeURIComponent(clientId)}&` +
|
|
8109
|
+
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
|
|
8110
|
+
`scope=email,public_profile&` +
|
|
8111
|
+
`response_type=code&` +
|
|
8112
|
+
`state=${encodeURIComponent(state)}`;
|
|
8113
|
+
break;
|
|
8114
|
+
case 'google':
|
|
8115
|
+
authUrl = `https://accounts.google.com/o/oauth2/v2/auth?` +
|
|
8116
|
+
`client_id=${encodeURIComponent(clientId)}&` +
|
|
8117
|
+
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
|
|
8118
|
+
`scope=openid%20email%20profile&` +
|
|
8119
|
+
`response_type=code&` +
|
|
8120
|
+
`state=${encodeURIComponent(state)}`;
|
|
8121
|
+
break;
|
|
8122
|
+
default:
|
|
8123
|
+
response.status(400).json({
|
|
8124
|
+
error: 'Unsupported provider',
|
|
8125
|
+
message: `Social authentication provider '${provider}' is not supported. Supported providers: facebook, google`
|
|
8126
|
+
});
|
|
8127
|
+
return;
|
|
8128
|
+
}
|
|
8129
|
+
// Log the OAuth attempt for debugging
|
|
8130
|
+
if (isVerbose) {
|
|
8131
|
+
console.info(colors__default["default"].cyan(`OAuth ${provider} flow started for app ${appId || 'default'}`));
|
|
8132
|
+
}
|
|
8133
|
+
response.json({
|
|
8134
|
+
authUrl,
|
|
8135
|
+
provider,
|
|
8136
|
+
state,
|
|
8137
|
+
message: `Redirect user to authUrl to complete ${provider} authentication`
|
|
8138
|
+
});
|
|
8139
|
+
}
|
|
8140
|
+
catch (error) {
|
|
8141
|
+
assertsError(error);
|
|
8142
|
+
console.warn(`OAuth ${provider} initialization failed:`, error);
|
|
8143
|
+
response.status(500).json({
|
|
8144
|
+
error: 'OAuth initialization failed',
|
|
8145
|
+
message: error.message
|
|
8146
|
+
});
|
|
8147
|
+
}
|
|
8148
|
+
});
|
|
8149
|
+
app.post('/auth/:provider/callback', async (request, response) => {
|
|
8150
|
+
const { provider } = request.params;
|
|
8151
|
+
if (!isApplicationModeAllowed || login === null) {
|
|
8152
|
+
response.status(400).json({
|
|
8153
|
+
error: 'Application mode is not allowed',
|
|
8154
|
+
message: 'Social authentication requires application mode and login handler to be configured'
|
|
8155
|
+
});
|
|
8156
|
+
return;
|
|
8157
|
+
}
|
|
8158
|
+
try {
|
|
8159
|
+
const { code, state, error: oauthError } = request.body;
|
|
8160
|
+
if (oauthError) {
|
|
8161
|
+
response.status(400).json({
|
|
8162
|
+
isSuccess: false,
|
|
8163
|
+
error: 'OAuth authorization failed',
|
|
8164
|
+
message: `${provider} authentication was denied or failed: ${oauthError}`
|
|
8165
|
+
});
|
|
8166
|
+
return;
|
|
8167
|
+
}
|
|
8168
|
+
if (!code || !state) {
|
|
8169
|
+
response.status(400).json({
|
|
8170
|
+
isSuccess: false,
|
|
8171
|
+
error: 'Missing OAuth callback parameters',
|
|
8172
|
+
message: 'code and state parameters are required'
|
|
8173
|
+
});
|
|
8174
|
+
return;
|
|
8175
|
+
}
|
|
8176
|
+
// Decode state to get app information
|
|
8177
|
+
let appInfo;
|
|
8178
|
+
try {
|
|
8179
|
+
appInfo = JSON.parse(Buffer.from(state, 'base64').toString());
|
|
8180
|
+
}
|
|
8181
|
+
catch (_a) {
|
|
8182
|
+
response.status(400).json({
|
|
8183
|
+
isSuccess: false,
|
|
8184
|
+
error: 'Invalid state parameter',
|
|
8185
|
+
message: 'The OAuth state parameter is malformed'
|
|
8186
|
+
});
|
|
8187
|
+
return;
|
|
8188
|
+
}
|
|
8189
|
+
// Log the OAuth callback for debugging
|
|
8190
|
+
if (isVerbose) {
|
|
8191
|
+
console.info(colors__default["default"].cyan(`OAuth ${provider} callback received for app ${appInfo.appId}`));
|
|
8192
|
+
}
|
|
8193
|
+
// Note: In a real implementation, you would:
|
|
8194
|
+
// 1. Exchange the code for an access token with the OAuth provider
|
|
8195
|
+
// 2. Use the access token to get user information
|
|
8196
|
+
// 3. Create or find the user in your system
|
|
8197
|
+
// 4. Call the login function with the user's information
|
|
8198
|
+
// For now, we provide a framework that the implementer can extend
|
|
8199
|
+
const mockUserInfo = {
|
|
8200
|
+
username: `${provider}_user_${code.substring(0, 8)}`,
|
|
8201
|
+
password: '',
|
|
8202
|
+
appId: appInfo.appId
|
|
8203
|
+
};
|
|
8204
|
+
const loginResult = await login({
|
|
8205
|
+
...mockUserInfo,
|
|
8206
|
+
rawRequest: request,
|
|
8207
|
+
rawResponse: response,
|
|
8208
|
+
});
|
|
8209
|
+
response.status(200).json({
|
|
8210
|
+
...loginResult,
|
|
8211
|
+
provider,
|
|
8212
|
+
message: loginResult.message || `${provider} authentication completed`,
|
|
8213
|
+
});
|
|
8214
|
+
}
|
|
8215
|
+
catch (error) {
|
|
8216
|
+
assertsError(error);
|
|
8217
|
+
console.warn(`OAuth ${provider} callback failed:`, error);
|
|
8218
|
+
response.status(500).json({
|
|
8219
|
+
isSuccess: false,
|
|
8220
|
+
error: 'OAuth callback processing failed',
|
|
8221
|
+
message: error.message
|
|
8222
|
+
});
|
|
8223
|
+
}
|
|
8224
|
+
});
|
|
8079
8225
|
app.get(`/books`, async (request, response) => {
|
|
8080
8226
|
if (collection === null) {
|
|
8081
8227
|
response.status(500).send('No collection available');
|