diff --git a/src/wwPlugin.js b/src/wwPlugin.js index 38f5c04..0f6fd79 100644 --- a/src/wwPlugin.js +++ b/src/wwPlugin.js @@ -46,6 +46,14 @@ export default { Editor API \================================================================================================*/ /* wwEditor:start */ + _getCopilotContext() { + return { + loginEndpoint: this.settings.publicData.loginEndpoint, + signupEndpoint: this.settings.publicData.signupEndpoint, + getMeEndpoint: this.settings.publicData.getMeEndpoint, + socialProviders: this.settings.publicData.socialProviders, + }; + }, async initManager(settings) { this.xanoManager = this.createManager(settings); try { diff --git a/ww-config.js b/ww-config.js index 4e4cd06..23b2a8a 100644 --- a/ww-config.js +++ b/ww-config.js @@ -67,6 +67,37 @@ export default { getIsValid({ parameters, body }) { return !parameters || body; }, + copilot: { + description: + 'Register a new user in Xano. On success, automatically stores the auth token and fetches the user profile.', + returns: 'object - The newly created user profile data', + schema: { + body: { + type: 'object', + description: + 'Request body containing user registration data. Must match your Xano API endpoint schema. The key values are bindable, but not the whole object. The object cannot be bind, you have to bind individual sub keys. eg. {email: {__wwType: "...", code: "..."}, password {__wwType: "...", code: "..."}}', + bindable: false, + }, + parameters: { + type: 'object', + description: + 'Add query parameters to URL. Example: {"userId": "123", "filter": "active"}. The values are bindable, but not the whole object.', + bindable: false, + }, + headers: { + type: 'Array<{key: string, value: string}', + description: + 'Custom headers as key-value pairs, e.g., [{"Content-Type": "application/json"}]. Automatically includes Xano authentication token if available. key and value are bindable individually.', + bindable: true, + }, + withCredentials: { + type: 'boolean', + description: + 'Whether to include credentials (cookies) with the request. Falls back to plugin settings if not specified.', + bindable: false, + }, + }, + }, /* wwEditor:end */ }, { @@ -78,6 +109,37 @@ export default { getIsValid({ parameters, body }) { return !parameters || body; }, + copilot: { + description: + 'Authenticate a user with Xano. On success, automatically stores the auth token and fetches the user profile.', + returns: 'object - The authenticated user profile data', + schema: { + body: { + type: 'object', + description: + 'Request body containing login credentials. Must match your Xano API endpoint schema. The object cannot be bind, you have to bind individual sub keys. eg. {email: {__wwType: "...", code: "..."}, password {__wwType: "...", code: "..."}}', + bindable: false, + }, + parameters: { + type: 'object', + description: + 'Add query parameters to URL. Example: {"userId": "123", "filter": "active"}. The values are bindable, but not the whole object.', + bindable: false, + }, + headers: { + type: 'Array<{key: string, value: string}', + description: + 'Custom headers as key-value pairs, e.g., [{"Content-Type": "application/json"}]. Automatically includes Xano authentication token if available. key and value are bindable individually.', + bindable: true, + }, + withCredentials: { + type: 'boolean', + description: + 'Whether to include credentials (cookies) with the request. Falls back to plugin settings if not specified.', + bindable: false, + }, + }, + }, /* wwEditor:end */ }, { @@ -89,6 +151,41 @@ export default { getIsValid({ provider, type }) { return !!provider && !!type; }, + copilot: { + description: + "Initiate OAuth social login with a specified provider (e.g., Google, Facebook). Opens the provider's authentication window.", + returns: "void - Redirects to the provider's auth page", + schema: { + provider: { + type: 'string', + description: 'The name of the social provider as configured in your Xano settings', + bindable: true, + }, + type: { + type: 'string', + description: + 'The type of OAuth flow to use. For twitter-oauth, use "access_token", for the rest, use "continue"', + bindable: true, + }, + redirectPage: { + type: 'string', + description: 'The page path to redirect to after successful authentication', + bindable: true, + }, + headers: { + type: 'Array<{key: string, value: string}', + description: + 'Custom headers as key-value pairs, e.g., [{"Content-Type": "application/json"}]. Automatically includes Xano authentication token if available. key and value are bindable individually.', + bindable: true, + }, + withCredentials: { + type: 'boolean', + description: + 'Whether to include credentials (cookies) with the request. Falls back to plugin settings if not specified.', + bindable: false, + }, + }, + }, /* wwEditor:end */ }, { @@ -97,6 +194,25 @@ export default { isAsync: true, /* wwEditor:start */ edit: () => import('./src/components/Functions/FetchUser.vue'), + copilot: { + description: + "Fetch the current authenticated user's profile from Xano. Updates the internal user state and isAuthenticated flag.", + returns: "object - The current user's profile data", + schema: { + headers: { + type: 'Array<{key: string, value: string}', + description: + 'Custom headers as key-value pairs, e.g., [{"Content-Type": "application/json"}]. Automatically includes Xano authentication token if available. key and value are bindable individually.', + bindable: true, + }, + withCredentials: { + type: 'boolean', + description: + 'Whether to include credentials (cookies) with the request. Falls back to plugin settings if not specified.', + bindable: false, + }, + }, + }, /* wwEditor:end */ }, { @@ -104,11 +220,31 @@ export default { code: 'storeAuthToken', /* wwEditor:start */ edit: () => import('./src/components/Functions/StoreAuthToken.vue'), + copilot: { + description: + 'Manually store a Xano authentication token. Updates the cookie, internal state, and configures the Xano client with the token.', + returns: 'void', + schema: { + authToken: { + type: 'string', + description: 'The authentication token to store', + bindable: true, + }, + }, + }, /* wwEditor:end */ }, { name: 'Logout', code: 'logout', + /* wwEditor:start */ + copilot: { + description: + 'Log out the current user. Clears the auth token, user data, and resets the authentication state.', + returns: 'void', + schema: {}, + }, + /* wwEditor:end */ }, ], };