becca_entities_betapi_token.js.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: becca/entities/betapi_token.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: becca/entities/betapi_token.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>"use strict";
  20. const dateUtils = require('../../services/date_utils');
  21. const AbstractBeccaEntity = require("./abstract_becca_entity");
  22. /**
  23. * EtapiToken is an entity representing token used to authenticate against Trilium REST API from client applications.
  24. * Used by:
  25. * - Trilium Sender
  26. * - ETAPI clients
  27. *
  28. * The format user is presented with is "&lt;etapiTokenId>_&lt;tokenHash>". This is also called "authToken" to distinguish it
  29. * from tokenHash and token.
  30. *
  31. * @extends AbstractBeccaEntity
  32. */
  33. class BEtapiToken extends AbstractBeccaEntity {
  34. static get entityName() { return "etapi_tokens"; }
  35. static get primaryKeyName() { return "etapiTokenId"; }
  36. static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; }
  37. constructor(row) {
  38. super();
  39. if (!row) {
  40. return;
  41. }
  42. this.updateFromRow(row);
  43. this.init();
  44. }
  45. updateFromRow(row) {
  46. /** @type {string} */
  47. this.etapiTokenId = row.etapiTokenId;
  48. /** @type {string} */
  49. this.name = row.name;
  50. /** @type {string} */
  51. this.tokenHash = row.tokenHash;
  52. /** @type {string} */
  53. this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
  54. /** @type {string} */
  55. this.utcDateModified = row.utcDateModified || this.utcDateCreated;
  56. /** @type {boolean} */
  57. this.isDeleted = !!row.isDeleted;
  58. if (this.etapiTokenId) {
  59. this.becca.etapiTokens[this.etapiTokenId] = this;
  60. }
  61. }
  62. init() {
  63. if (this.etapiTokenId) {
  64. this.becca.etapiTokens[this.etapiTokenId] = this;
  65. }
  66. }
  67. getPojo() {
  68. return {
  69. etapiTokenId: this.etapiTokenId,
  70. name: this.name,
  71. tokenHash: this.tokenHash,
  72. utcDateCreated: this.utcDateCreated,
  73. utcDateModified: this.utcDateModified,
  74. isDeleted: this.isDeleted
  75. }
  76. }
  77. beforeSaving() {
  78. this.utcDateModified = dateUtils.utcNowDateTime();
  79. super.beforeSaving();
  80. this.becca.etapiTokens[this.etapiTokenId] = this;
  81. }
  82. }
  83. module.exports = BEtapiToken;
  84. </code></pre>
  85. </article>
  86. </section>
  87. </div>
  88. <nav>
  89. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-sql.html">sql</a></li></ul><h3>Classes</h3><ul><li><a href="AbstractBeccaEntity.html">AbstractBeccaEntity</a></li><li><a href="BAttachment.html">BAttachment</a></li><li><a href="BAttribute.html">BAttribute</a></li><li><a href="BBranch.html">BBranch</a></li><li><a href="BEtapiToken.html">BEtapiToken</a></li><li><a href="BNote.html">BNote</a></li><li><a href="BOption.html">BOption</a></li><li><a href="BRecentNote.html">BRecentNote</a></li><li><a href="BRevision.html">BRevision</a></li><li><a href="BackendScriptApi.html">BackendScriptApi</a></li></ul><h3>Global</h3><ul><li><a href="global.html#api">api</a></li></ul>
  90. </nav>
  91. <br class="clear">
  92. <footer>
  93. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
  94. </footer>
  95. <script> prettyPrint(); </script>
  96. <script src="scripts/linenumber.js"> </script>
  97. </body>
  98. </html>