### Initialize and Use SDK with jQuery Source: https://github.com/versionone/versionone.sdk.javascript/blob/master/README.md Demonstrates initializing the SDK with jQuery for authentication using username/password and performing create, update, and query operations on 'Story' entities. Requires jQuery and the v1sdk to be installed. ```javascript import $ from 'jquery'; import sdk, {jqueryConnector} from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // usage with username/password // .withAccessToken('your token'); // usage with access tokens // .withImplicitAuth(); // let the browser do its thing v1.create('Story', {estimate: 5, status: 'Not Started'}) .then((story) => v1.update(story.oidToken, {estimate: 7})) .then(v1.query({ from: 'Story', select: ['Estimate', 'Status'], where: { Status: 'Not Started' } })) .then(console.log) .catch(console.log); ``` -------------------------------- ### Configure CORS in user.config (Multiple Domains) Source: https://github.com/versionone/versionone.sdk.javascript/blob/master/README.md Example of an XML configuration file to enable Cross-origin resource sharing (CORS) for multiple domains in an on-premise VersionOne instance. ```xml ``` -------------------------------- ### Configure CORS in user.config (Single Domain) Source: https://github.com/versionone/versionone.sdk.javascript/blob/master/README.md Example of an XML configuration file to enable Cross-origin resource sharing (CORS) for a single domain in an on-premise VersionOne instance. ```xml ``` -------------------------------- ### Get Activity Stream for an Asset Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Retrieves the activity stream for a specific asset (e.g., Story, Defect). Requires the SDK to be initialized with credentials. ```javascript import $ from 'jquery'; import sdk, { jqueryConnector } from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Get activity stream for a story v1.getActivityStream('Story:12345') .then((activities) => { console.log('Activity stream:', activities); activities.forEach(activity => { console.log(`${activity.timestamp}: ${activity.description}`); }); }) .catch((error) => { console.error('Failed to get activity stream:', error); }); // Get activity stream for a defect v1.getActivityStream('Defect:67890') .then((activities) => console.log('Defect history:', activities)) .catch(console.error); ``` -------------------------------- ### Query Definition (Meta) API Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt The `queryDefinition` method retrieves metadata about asset types including their attributes, operations, and relationships. Call without arguments to get all asset types, or provide an asset type name to get specific metadata. ```APIDOC ## Query Definition (Meta) ### Description Retrieves metadata for VersionOne asset types, including attributes, operations, and relationships. ### Method GET (implicitly via SDK method) ### Endpoint Not directly exposed as a REST endpoint; invoked via SDK method. ### Parameters #### Arguments for `v1.queryDefinition` method - **assetTypeName** (string) - Optional - The name of the asset type to get metadata for (e.g., 'Story', 'Defect'). If omitted, metadata for all asset types is returned. ### Request Example ```javascript // Get metadata for Story asset type v1.queryDefinition('Story') .then((metadata) => { console.log('Story metadata:', metadata); }) .catch(console.error); // Get metadata for all asset types v1.queryDefinition() .then((allMetadata) => { console.log('All asset types:', Object.keys(allMetadata)); }) .catch(console.error); ``` ### Response #### Success Response (200) - **Object** - Contains metadata for the requested asset type(s). Includes `Attributes`, `Operations`, and `Relationships`. ``` -------------------------------- ### Query Asset Definitions (Metadata) Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Use `queryDefinition` to get metadata about asset types, including attributes and operations. Call without arguments for all asset types, or provide an asset type name for specific metadata. ```javascript import $ from 'jquery'; import sdk, { jqueryConnector } from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Get metadata for Story asset type v1.queryDefinition('Story') .then((metadata) => { console.log('Story metadata:', metadata); console.log('Available attributes:', Object.keys(metadata.Attributes)); console.log('Available operations:', Object.keys(metadata.Operations)); }) .catch(console.error); // Get metadata for all asset types v1.queryDefinition() .then((allMetadata) => { console.log('All asset types:', Object.keys(allMetadata)); }) .catch(console.error); // Get Defect metadata to discover available fields v1.queryDefinition('Defect') .then((metadata) => { console.log('Defect attributes:', metadata.Attributes); // Use this to discover valid attribute names for create/update/query }) .catch(console.error); ``` -------------------------------- ### Initialize SDK with Different Connectors and Authentication Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Demonstrates initializing the SDK using either jQuery or Axios connectors with username/password, access token, or implicit browser authentication. Ensure your VersionOne instance is version 17.1 or later. ```javascript import $ from 'jquery'; import axios from 'axios'; import sdk, {jqueryConnector, axiosConnector, Oid} from 'v1sdk'; // Using jQuery connector with username/password authentication const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1WithCreds = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Using Axios connector with access token authentication const axiosConnectedSdk = axiosConnector(axios)(sdk); const v1WithToken = axiosConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withAccessToken('your-access-token-here'); // Using implicit browser authentication (for browser-side when CORS is enabled) const v1Implicit = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withImplicitAuth(); ``` -------------------------------- ### Create New VersionOne Assets Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Shows how to create new assets like 'Story' or 'Defect' using the `create` method. Provide the asset type and an object with attributes. Relational attributes can be set using arrays of OIDs. The method returns a Promise resolving with the created asset's data. ```javascript import $ from 'jquery'; import sdk, {jqueryConnector} from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Create a new Story with estimate and status v1.create('Story', { Name: 'Implement user login feature', Estimate: 5, Status: 'Not Started', Description: 'As a user, I want to log in to the application' }) .then((createdStory) => { console.log('Created Story:', createdStory); console.log('OID Token:', createdStory.oidToken); // e.g., 'Story:12345' }) .catch((error) => { console.error('Failed to create story:', error); }); // Create a Defect with relational attributes (array values reference other assets) v1.create('Defect', { Name: 'Login button not responding', Priority: 'High', Owners: ['Member:20', 'Member:21'] // Assign multiple owners by OID }) .then((defect) => console.log('Created Defect:', defect.oidToken)) .catch(console.error); ``` -------------------------------- ### Query Assets with VersionOne SDK Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Use the `query` method to retrieve assets. Specify the asset type in `from` and attributes in `select`. Filters can be applied using `where`, `sort`, and `page` parameters. ```javascript import $ from 'jquery'; import sdk, { jqueryConnector } from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Query stories with specific status v1.query({ from: 'Story', select: ['Name', 'Estimate', 'Status', 'Owners.Name'], where: { Status: 'In Progress' } }) .then((results) => { console.log('Stories in progress:', results); results.forEach(story => { console.log(`${story.Name}: ${story.Estimate} points`); }); }) .catch(console.error); // Query defects with multiple conditions v1.query({ from: 'Defect', select: ['Name', 'Priority', 'Status', 'CreatedBy.Name', 'Scope.Name'], where: { Priority: 'High', Status: 'Open' } }) .then((defects) => { console.log('High priority open defects:', defects); }) .catch(console.error); // Query with relationship traversal v1.query({ from: 'Task', select: ['Name', 'Status', 'Parent.Name', 'Owners.Name', 'DetailEstimate'], where: { 'Parent.Status': 'In Progress' } }) .then((tasks) => console.log('Tasks for in-progress stories:', tasks)) .catch(console.error); ``` -------------------------------- ### Axios Connector for Node.js Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Adapts the SDK to use Axios for HTTP requests, suitable for server-side applications like Node.js. Demonstrates querying and Express.js integration. ```javascript import axios from 'axios'; import sdk, { axiosConnector } from 'v1sdk'; // Create SDK instance with Axios const axiosConnectedSdk = axiosConnector(axios)(sdk); const v1 = axiosConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Use in Node.js server async function getStories() { try { const stories = await v1.query({ from: 'Story', select: ['Name', 'Estimate', 'Status'] }); return stories; } catch (error) { console.error('Error fetching stories:', error); throw error; } } // Express.js integration example const express = require('express'); const app = express(); app.get('/api/stories', async (req, res) => { try { const stories = await v1.query({ from: 'Story', select: ['Name', 'Estimate', 'Status'], where: { Status: 'In Progress' } }); res.json(stories); } catch (error) { res.status(500).json({ error: error.message }); } }); ``` -------------------------------- ### Update Existing VersionOne Assets Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Demonstrates updating an existing asset using its `oidToken`. The `update` method takes the `oidToken`, an object with attributes to modify, and an optional change comment for auditing. It returns a Promise with the updated asset data. ```javascript import $ from 'jquery'; import sdk, {jqueryConnector} from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Update a story's estimate v1.update('Story:12345', { Estimate: 8, Status: 'In Progress' }) .then((updatedStory) => { console.log('Updated Story:', updatedStory); }) .catch((error) => { console.error('Failed to update story:', error); }); // Update with a change comment for audit trail v1.update('Story:12345', { Estimate: 13, Status: 'Done' }, 'Increased estimate after discovery of additional requirements') .then((updatedStory) => { console.log('Updated with comment:', updatedStory); }) .catch(console.error); // Chain create and update operations v1.create('Story', { Name: 'New Feature', Estimate: 3 }) .then((story) => v1.update(story.oidToken, { Estimate: 5 })) .then((updated) => console.log('Created and updated:', updated)) .catch(console.error); ``` -------------------------------- ### Parse and Validate OID Tokens Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Demonstrates parsing VersionOne OID tokens, extracting asset type and number, and handling invalid tokens. Useful for validating input before API calls. ```javascript import { Oid, InvalidOidToken } from 'v1sdk'; // Parse a valid OID token const oid = new Oid('Story:12345'); console.log('Asset Type:', oid.assetType); // 'Story' console.log('Asset Number:', oid.number); // 12345 console.log('String:', oid.toString()); // 'Story:12345' // Parse member OID const memberOid = new Oid('Member:20'); console.log('Member type:', memberOid.assetType); // 'Member' console.log('Member ID:', memberOid.number); // 20 // Handle invalid OID tokens try { const invalidOid = new Oid('Member:InvalidNumber'); } catch (error) { if (error instanceof InvalidOidToken) { console.error('Invalid OID token format:', error.message); } } // Use Oid for validation before API calls function processAsset(oidToken) { try { const oid = new Oid(oidToken); console.log(`Processing ${oid.assetType} with ID ${oid.number}`); return true; } catch (error) { console.error('Invalid OID token:', oidToken); return false; } } processAsset('Story:100'); // Processing Story with ID 100 processAsset('Invalid:abc'); // Invalid OID token: Invalid:abc ``` -------------------------------- ### Query Assets API Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt The `query` method retrieves assets using VersionOne's query API. The query object must include `from` (asset type) and `select` (array of attributes). Optional parameters include `where` (filter conditions), `sort`, and `page` for pagination. ```APIDOC ## Query Assets ### Description Retrieves assets using VersionOne's query API. Requires `from` and `select` parameters. Supports optional `where`, `sort`, and `page` for filtering and pagination. ### Method POST (implicitly via SDK method) ### Endpoint Not directly exposed as a REST endpoint; invoked via SDK method. ### Parameters #### Request Body (for `v1.query` method) - **from** (string) - Required - The asset type to query (e.g., 'Story', 'Defect'). - **select** (array of strings) - Required - An array of attributes to retrieve for each asset. - **where** (object) - Optional - Filter conditions for the query. Can include nested conditions for relationships. - **sort** (object) - Optional - Sorting criteria for the results. - **page** (object) - Optional - Pagination parameters. ### Request Example ```javascript v1.query({ from: 'Story', select: ['Name', 'Estimate', 'Status', 'Owners.Name'], where: { Status: 'In Progress' } }) .then((results) => { console.log('Stories in progress:', results); }) .catch(console.error); ``` ### Response #### Success Response (200) - **Array of asset objects** - Each object contains the selected attributes. ``` -------------------------------- ### jQuery Connector for Browser Apps Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt Adapts the SDK to use jQuery AJAX for HTTP requests, suitable for browser-based applications. Shows Promise chaining for queries and a full CRUD workflow. ```javascript import $ from 'jquery'; import sdk, { jqueryConnector } from 'v1sdk'; // Create SDK instance with jQuery const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withAccessToken('your-access-token'); // Browser-side usage with Promise chaining v1.query({ from: 'Story', select: ['Name', 'Estimate', 'Status'] }) .then((stories) => { // Update DOM with story data stories.forEach(story => { $('#story-list').append(`
  • ${story.Name} - ${story.Estimate} pts
  • `); }); }) .catch((error) => { $('#error-message').text('Failed to load stories: ' + error.message); }); // Full CRUD workflow example v1.create('Story', { Name: 'New User Story', Estimate: 5, Status: 'Not Started' }) .then((story) => { console.log('Created:', story.oidToken); return v1.update(story.oidToken, { Estimate: 8 }); }) .then((story) => { console.log('Updated estimate'); return v1.query({ from: 'Story', select: ['Name', 'Estimate', 'Status'], where: { Status: 'Not Started' } }); }) .then((stories) => console.log('All pending stories:', stories)) .catch(console.error); ``` -------------------------------- ### Execute Operations with VersionOne SDK Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt The `executeOperation` method invokes predefined actions on assets. Provide the asset's OID token and the operation name. This is used for actions like 'Inactivate', 'Delete', or 'Reactivate'. ```javascript import $ from 'jquery'; import sdk, { jqueryConnector } from 'v1sdk'; const jqueryConnectedSdk = jqueryConnector($)(sdk); const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) .withCreds('admin', 'admin'); // Close a completed story v1.executeOperation('Story:12345', 'Inactivate') .then((result) => { console.log('Story closed successfully:', result); }) .catch((error) => { console.error('Failed to close story:', error); }); // Delete a defect v1.executeOperation('Defect:67890', 'Delete') .then((result) => console.log('Defect deleted:', result)) .catch(console.error); // Reactivate an inactive asset v1.executeOperation('Story:12345', 'Reactivate') .then((result) => console.log('Story reactivated:', result)) .catch(console.error); // Complete workflow: create, update, and close a story v1.create('Story', { Name: 'Quick fix', Estimate: 1 }) .then((story) => v1.update(story.oidToken, { Status: 'Done' })) .then((story) => v1.executeOperation(story.oidToken, 'Inactivate')) .then((result) => console.log('Story completed and closed')) .catch(console.error); ``` -------------------------------- ### Execute Operation API Source: https://context7.com/versionone/versionone.sdk.javascript/llms.txt The `executeOperation` method invokes a VersionOne operation on an asset. Operations are predefined actions like 'Inactivate', 'Delete', 'Close', or custom operations defined in your VersionOne instance. ```APIDOC ## Execute Operation ### Description Invokes a predefined or custom operation on a specific VersionOne asset. ### Method POST (implicitly via SDK method) ### Endpoint Not directly exposed as a REST endpoint; invoked via SDK method. ### Parameters #### Arguments for `v1.executeOperation` method - **assetIdToken** (string) - Required - The unique identifier token of the asset (e.g., 'Story:12345'). - **operationName** (string) - Required - The name of the operation to execute (e.g., 'Inactivate', 'Delete', 'Close'). ### Request Example ```javascript v1.executeOperation('Story:12345', 'Inactivate') .then((result) => { console.log('Story closed successfully:', result); }) .catch((error) => { console.error('Failed to close story:', error); }); ``` ### Response #### Success Response (200) - **Object** - Typically indicates success, may contain details about the operation's outcome. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.