### Start Local Development Environment with Docker Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Starts a Docker container, mounting the current directory to /opt/NetLicensingClient-javascript and running bash. ```bash docker run -v $(pwd):/opt/NetLicensingClient-javascript -i -t labs64/nodejs /bin/bash ``` -------------------------------- ### Install NetLicensing Client with npm Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Add the NetLicensing JavaScript Client as a dependency to your project's package.json file and run 'npm install'. ```json "dependencies": { "netlicensing-client": "x.y.z" } ``` -------------------------------- ### Install NetLicensing Client via npm command Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Alternatively, install the NetLicensing JavaScript Client directly in your Node.js environment using the npm install command. ```bash $ npm install netlicensing-client ``` -------------------------------- ### Get a Product by Number Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Retrieves a specific product entity from NetLicensing using its unique number. The returned promise resolves with the product details. ```javascript NetLicensing.ProductService.get(context, 'PRODUCT_NUMBER') //ProductService.get returns promise with product entity .then(function (product) { console.log(product.getProperties()); }) ``` -------------------------------- ### Create a Product Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Shows how to create a new product entity and send the creation request to the NetLicensing API. Ensure the product object is properly configured before sending. ```javascript var product = new NetLicensing.Product() .setNumber('PRODUCT_NUMBER') .setName('PRODUCT_NAME') .setVersion('PRODUCT_VERSION') .setActive(true); //boolean value true|false // send request using NetLicensing RESTful API NetLicensing.ProductService.create(context, product) //ProductService.create returns promise with product entity .then(function (product) { console.log(product.getProperties()); }) ``` -------------------------------- ### Run Development Server Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Builds and tracks changes to resources during development. ```bash npm run dev ``` -------------------------------- ### List All Products Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Fetches a list of all products available in NetLicensing. The result is a promise that resolves with an array of product entities. ```javascript NetLicensing.ProductService.list(context) //ProductService.list returns promise with array products entities .then(function (products) { var length = products.length; for (var i = 0; i < length; i++) { console.log(products[i].getProperties()); } }) ``` -------------------------------- ### Create Authentication Context for NetLicensing API Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Demonstrates how to create authentication contexts for both Basic Authentication and API Key identification. Use this to authenticate your requests to the NetLicensing RESTful API. ```javascript var client = require('netlicensing-client'); //create Basic Auth context var context = new client.Context() .setUsername('YOUR_NETLICENSING_USERNAME') .setPassword('YOUR_NETLICENSING_PASSWORD') .setSecurityMode(NetLicensing.Constants.BASIC_AUTHENTICATION); // ... or ... //create APIKey auth context var context = new NetLicensing.Context() .setApiKey("YOUR_NETLICENSING_API_KEY") .setSecurityMode(NetLicensing.Context.APIKEY_IDENTIFICATION); ``` ```javascript //use NetLicensing RESTful API - https://www.labs64.de/confluence/x/pwCo var validationParameters = new NetLicensing.ValidationParameters() .setLicenseeSecret('LICENSEE_SECRET') // optional .setLicenseeName('LICENSEE_NAME') // optional .setProductNumber('PRODUCT_NUMBER'); // optional NetLicensing.LicenseeService.validate(context, 'LICENSEE_NUMBER', validationParameters) .then(function (validationResult) { console.log(validationResult.getValidators()); }) ``` -------------------------------- ### Build Docker Image Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Builds a Docker image tagged as labs64/nodejs from the current directory. ```bash docker build -t labs64/nodejs . ``` -------------------------------- ### Run Unit Tests Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Executes the project's unit tests. ```bash npm run test ``` -------------------------------- ### Clone Repository Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Clones the NetLicensingClient-javascript repository from GitHub. ```bash git clone https://github.com/Labs64/NetLicensingClient-javascript.git ``` -------------------------------- ### Create Shop Token Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Generates a shop token for a specific licensee, which can be used to create a shop URL. The token creation process returns a promise with the token details. ```javascript var token = new NetLicensing.Token() .setTokenType(NetLicensing.Token.TOKEN_TYPE_SHOP) .setLicenseeNumber('LICENSEE_NUMBER'); NetLicensing.TokenService.create(context, token) //return promise with created token .then(function (token) { console.log(token.getProperties()); console.log('Shop URL:' + token.getShopURL()); }); ``` -------------------------------- ### Run Linter Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Performs a syntax check on the project's code. ```bash npm run lint ``` -------------------------------- ### Include NetLicensing Client from local distribution Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Include the compiled NetLicensing JavaScript Client files from your project's local 'dist' directory in your HTML page. ```html ``` -------------------------------- ### Configure Git Username Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Sets the global Git username configuration. ```bash git config --global user.name "User Name" ``` -------------------------------- ### Configure Git Email Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Sets the global Git email configuration. ```bash git config --global user.email "eMail" ``` -------------------------------- ### Basic Page Styling Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/docs/index.html CSS rules to style the page, setting a sans-serif font, centering content, and defining link styles. ```css body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f9fafb; color: #374151; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; text-align: center; } .container { max-width: 500px; padding: 2rem; } a { color: #E14817; /* Labs64 Brand Color */ text-decoration: none; font-weight: 600; } a:hover { text-decoration: underline; } ``` -------------------------------- ### Update a Product Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Updates an existing product in NetLicensing with new details. The API call returns a promise that resolves with the updated product entity. ```javascript NetLicensing.ProductService.update(context, 'PRODUCT_NUMBER', productForUpdate) //ProductService.update return promise with updated product entity .then(function (product) { console.log(product.getProperties()); }) ``` -------------------------------- ### Include NetLicensing Client from CDN Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/README.md Include the compiled and minified NetLicensing JavaScript Client from a CDN in the head section of your HTML page. Replace 'x.y.z' with the latest released version. ```html ``` -------------------------------- ### JavaScript Redirect Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/docs/index.html This snippet handles redirection to 'client-demo.html' using JavaScript. It's a fallback for when meta refresh is disabled. ```javascript window.location.href = "client-demo.html"; ``` -------------------------------- ### Validate Licensee Source: https://github.com/labs64/netlicensingclient-javascript/wiki/Home Validates a licensee against a product using provided parameters. This is crucial for checking license status and is used within the NetLicensing RESTful API. ```javascript var validationParameters = new NetLicensing.ValidationParameters() .setLicenseeSecret('LICENSEE_SECRET') .setLicenseeName('LICENSEE_NAME') .setProductNumber('PRODUCT_NUMBER'); NetLicensing.LicenseeService.validate(context, 'LICENSEE_NUMBER', validationParameters) .then(function (validationResult) { console.log(validationResult.getValidators()); }) ``` -------------------------------- ### Enhanced Console Logging for JavaScript Source: https://github.com/labs64/netlicensingclient-javascript/blob/master/docs/client-demo.html This snippet overrides the default console methods (log, error, warn) to append output to a specific HTML element. It handles multi-line output by creating foldable 'details' elements and formats arguments, including objects and errors, for better readability. ```javascript // Helper function for the Expand/Collapse buttons function toggleAllLogs(expand) { const details = document.querySelectorAll('#console-log-text details'); details.forEach(detail => { if (expand) { detail.setAttribute('open', ''); } else { detail.removeAttribute('open'); } }); } (function() { const oldLog = console.log; const oldError = console.error; const oldWarn = console.warn; const logger = document.getElementById('console-log-text'); function formatArgs(args) { return Array.from(args).map(arg => { if (arg instanceof Error) { return arg.stack || arg.message; } if (typeof arg === 'object' && arg !== null) { try { return JSON.stringify(arg, null, 2); } catch (e) { return String(arg); } } return String(arg); }).join(' '); } function appendLog(args, colorClass, prefixChar = '>') { const msg = formatArgs(args); const lines = msg.split('\n'); // If it's a multi-line output (like an API JSON response), make it foldable if (lines.length > 1) { const details = document.createElement('details'); details.className = `log-entry ${colorClass} group`; const summary = document.createElement('summary'); summary.className = 'cursor-pointer hover:opacity-80 transition-opacity outline-none flex items-start select-none'; // Arrow indicator that rotates when expanded const arrow = document.createElement('span'); arrow.className = 'text-\[#E14817\] mr-2 font-bold transform transition-transform group-open:rotate-90 inline-block w-3 flex-shrink-0 text-center'; arrow.textContent = prefixChar; const summaryText = document.createElement('span'); // Show the first line with an ellipsis, so the user knows there is hidden data summaryText.textContent = lines[0] + ' ...'; summaryText.className = 'truncate'; summary.appendChild(arrow); summary.appendChild(summaryText); const content = document.createElement('div'); // Indent the expanded JSON, add a subtle border on the left content.className = 'pl-4 ml-\[0.35rem\] border-l-2 border-gray-700 mt-1 whitespace-pre-wrap break-all opacity-90'; content.textContent = lines.slice(1).join('\n'); details.appendChild(summary); details.appendChild(content); logger.appendChild(details); } // Single line output (like a basic string log) else { const div = document.createElement('div'); div.className = `log-entry ${colorClass} flex items-start`; const prefix = document.createElement('span'); prefix.className = 'text-\[#E14817\] mr-2 select-none font-bold inline-block w-3 flex-shrink-0 text-center'; prefix.textContent = prefixChar; const text = document.createElement('span'); text.className = 'whitespace-pre-wrap break-all'; text.textContent = msg; div.appendChild(prefix); div.appendChild(text); logger.appendChild(div); } requestAnimationFrame(() => { logger.scrollTop = logger.scrollHeight; }); } console.log = function() { oldLog.apply(console, arguments); appendLog(arguments, 'text-terminal-text'); }; console.error = function() { oldError.apply(console, arguments); appendLog(arguments, 'text-red-400', '✖'); }; console.warn = function() { oldWarn.apply(console, arguments); appendLog(arguments, 'text-yellow-400', '⚠'); }; window.onerror = function(message, source, lineno, colno, error) { console.error("Uncaught Error: " + message); return false; }; window.addEventListener("unhandledrejection", function(event) { console.error("Unhandled Promise Rejection: " + (event.reason ? event.reason.stack || event.reason : event)); }); window.clearBox = function(elementID) { const el = document.getElementById(elementID); if (el) { el.innerHTML = '