UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2 kB
{"version":3,"file":"get-license-key.mjs","names":[],"sources":["../../../src/services/options/get-license-key.ts"],"sourcesContent":["import { copy } from \"../../libs/i18n/index.js\";\nimport { OptionsRepository } from \"../../libs/repositories/index.js\";\nimport { decrypt } from \"../../utils/helpers/encrypt-decrypt.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\nimport { getLicenseOptionName } from \"../license/helpers/option-names.js\";\n\nconst getLicenseKey: ServiceFn<[], string> = async (context) => {\n\tconst Options = new OptionsRepository(context.db.client, context.config.db);\n\tconst tenantKey = context.request.tenantKey ?? null;\n\n\tconst licenseKeyRes = await Options.selectSingle({\n\t\tselect: [\"name\", \"value_text\"],\n\t\twhere: [\n\t\t\t{\n\t\t\t\tkey: \"name\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: getLicenseOptionName(tenantKey, \"license_key\"),\n\t\t\t},\n\t\t],\n\t});\n\tif (licenseKeyRes.error) return licenseKeyRes;\n\n\tconst encryptedKey = licenseKeyRes.data?.value_text;\n\tconst licenseKey = encryptedKey\n\t\t? decrypt(encryptedKey, context.config.secrets.encryption)\n\t\t: undefined;\n\n\tif (!licenseKey?.trim()) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tstatus: 400,\n\t\t\t\tmessage: copy(\"server:core.license.is.not.set\"),\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: licenseKey,\n\t};\n};\n\nexport default getLicenseKey;\n"],"mappings":"gPAMA,MAAM,EAAuC,KAAO,IAAY,CAC/D,IAAM,EAAU,IAAI,EAAkB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAAE,EACpE,EAAY,EAAQ,QAAQ,WAAa,KAEzC,EAAgB,MAAM,EAAQ,aAAa,CAChD,OAAQ,CAAC,OAAQ,YAAY,EAC7B,MAAO,CACN,CACC,IAAK,OACL,SAAU,IACV,MAAO,EAAqB,EAAW,aAAa,CACrD,CACD,CACD,CAAC,EACD,GAAI,EAAc,MAAO,OAAO,EAEhC,IAAM,EAAe,EAAc,MAAM,WACnC,EAAa,EAChB,EAAQ,EAAc,EAAQ,OAAO,QAAQ,UAAU,EACvD,IAAA,GAaH,OAXK,GAAY,KAAK,EAWf,CACN,MAAO,IAAA,GACP,KAAM,CACP,EAbQ,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,QAAS,EAAK,gCAAgC,CAC/C,EACA,KAAM,IAAA,EACP,CAOF"}