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;;;GAIG;AACH,2BAAiC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAKrG;AAED;;;GAGG;AACH,0CAAgD,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKvG;AAED;;;GAGG;AACH,6BAAmC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKvG;AAED;;;GAGG;AACH,sCAA4C,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAMhF","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"import axios from 'axios'\n\nconst API_URL = 'https://api.lisenser.com/v1'\n\n/**\n * Request object for licensing-related operations.\n */\nexport interface LicenseRequest {\n /**\n * The license key.\n */\n licenseKey: string\n /**\n * The machine ID.\n */\n machineId: string\n /**\n * The product ID.\n */\n productId: string\n /**\n * An inconsequential flag to indicate whether or not this request\n * is made as polling to check license status rather than a one-off check\n */\n polling?: boolean\n}\n\n/**\n * Status of a license.\n */\nexport interface LicenseStatus {\n /**\n * Indicates whether the license is currently active.\n */\n isActive: boolean\n /**\n * The current status of the license.\n * One of 'expired', 'active', 'invalid', or 'no-key'.\n */\n status: 'expired' | 'active' | 'invalid' | 'no-key'\n /**\n * The number of days until the license expires, if applicable.\n * `null` if the license is not set to expire.\n */\n daysToExpiry: number | null\n /**\n * indicating whether or not the License has been activated by\n * a different machine\n */\n isConflict?: boolean\n /**\n * List of features allowed to this license\n */\n features?: {feature: string}[]\n}\n\n/**\n * Status of a trial period.\n */\nexport interface TrialStatus {\n /**\n * Indicates whether the trial period is currently active.\n */\n isActive: boolean\n /**\n * The current status of the trial period.\n * One of 'expired', 'active', 'not-started', or 'not-allowed'.\n */\n status: 'expired' | 'active' | 'not-started' | 'not-allowed'\n /**\n * The number of days until the trial period expires.\n */\n daysToExpiry: number\n /**\n * List of features allowed in trial mode\n */\n features?: {feature: string}[]\n}\n\n/**\n * Possible statuses of trial period activation.\n */\nexport type TrialActivationStatus = 'started' | 'not-allowed' | 'conflict'\n\n/**\n * Returns the current status of a license.\n * @param req The license request.\n */\nexport async function getLicenseStatus(req: LicenseRequest): Promise<LicenseStatus> {\n const { licenseKey: key, machineId, productId } = req\n const urlSuffix = req.polling ? '?plg=true' : ''\n const url = `${API_URL}/license/status${urlSuffix}`\n const resp = await axios.post<{data: LicenseStatus}>(url, { key, machineId, productId }, getHeaders())\n\n return resp.data.data\n}\n\n/**\n * Activates a license key.\n * @param req The license request.\n */\nexport async function activateLicenseKey(req: LicenseRequest): Promise<LicenseStatus> {\n const { licenseKey: key, machineId, productId } = req\n const url = `${API_URL}/license/activate`\n const resp = await axios.post<{data: LicenseStatus}>(url, { key, machineId, productId }, getHeaders())\n\n return resp.data.data\n}\n\n/**\n * Returns the current status of a trial period.\n * @param productId The ID of the product for which to retrieve the trial status.\n * @param machineId The machine ID for which to retrieve the trial status.\n */\nexport async function getTrialStatus(productId: string, machineId: string): Promise<TrialStatus> {\n const url = `${API_URL}/trial/status`\n const resp = await axios.post<{data: TrialStatus}>(url, { machineId, productId }, getHeaders())\n\n return resp.data.data\n}\n\n/**\n * Activates a trial period.\n * @param productId The ID of the product for which to activate the trial period.\n * @param machineId The machine ID for which to activate the trial period.\n */\nexport async function startTrial(productId: string, machineId: string): Promise<TrialActivationStatus> {\n const url = `${API_URL}/trial/activate`\n const resp = await axios.post<{data: TrialActivationStatus}>(url, { machineId, productId }, getHeaders())\n\n return resp.data.data\n}\n\n/**\n * Requests an OTP code to be sent for license reset.\n * @param req The license reset request.\n */\nexport async function requestOtpForLicenseReset(productId: string, licenseKey: string): Promise<boolean> {\n const url = `${API_URL}/license/reset/send-otp`\n const resp = await axios.post<{data: {sent: boolean}}>(url, { key: licenseKey, productId }, getHeaders())\n\n return resp.data.data?.sent\n}\n\n/**\n * Commits a license reset using the provided OTP.\n * @param req The license reset commit request.\n */\nexport async function resetLicense(otp: string, productId: string, licenseKey: string): Promise<boolean> {\n const url = `${API_URL}/license/reset/commit`\n const resp = await axios.post<{data: {reset: boolean}}>(url, { key: licenseKey, productId, otp }, getHeaders())\n\n return resp.data.data?.reset\n}\n\n/**\n * Generates a third party token for the given license.\n * @param req The license request.\n */\nexport async function generate3rdPartyToken(req: LicenseRequest): Promise<string> {\n const { licenseKey: key, machineId, productId } = req\n const url = `${API_URL}/3rd-party-token/generate`\n const resp = await axios.post<{data: {token: string}}>(url, { key, machineId, productId }, getHeaders())\n\n return resp.data.data.token\n}\n\nfunction getHeaders() {\n // @ts-ignore\n if (typeof process === 'undefined') {\n return {}\n }\n\n // @ts-ignore\n const { platform } = process\n\n if (!platform) {\n return {}\n }\n\n return {\n headers: {\n 'User-Agent': `Lisenser JS SDK / ${platform}`,\n }\n }\n}"],"names":[],"version":3,"file":"types.d.ts.map"}