becca_entities_etapi_token.js.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: becca/entities/etapi_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/etapi_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 AbstractEntity = require("./abstract_entity");
  22. const sql = require("../../services/sql.js");
  23. /**
  24. * EtapiToken is an entity representing token used to authenticate against Trilium REST API from client applications.
  25. * Used by:
  26. * - Trilium Sender
  27. * - ETAPI clients
  28. *
  29. * The format user is presented with is "&lt;etapiTokenId>_&lt;tokenHash>". This is also called "authToken" to distinguish it
  30. * from tokenHash and token.
  31. */
  32. class EtapiToken extends AbstractEntity {
  33. static get entityName() { return "etapi_tokens"; }
  34. static get primaryKeyName() { return "etapiTokenId"; }
  35. static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; }
  36. constructor(row) {
  37. super();
  38. if (!row) {
  39. return;
  40. }
  41. this.updateFromRow(row);
  42. this.init();
  43. }
  44. updateFromRow(row) {
  45. /** @type {string} */
  46. this.etapiTokenId = row.etapiTokenId;
  47. /** @type {string} */
  48. this.name = row.name;
  49. /** @type {string} */
  50. this.tokenHash = row.tokenHash;
  51. /** @type {string} */
  52. this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
  53. /** @type {string} */
  54. this.utcDateModified = row.utcDateModified || this.utcDateCreated;
  55. /** @type {boolean} */
  56. this.isDeleted = !!row.isDeleted;
  57. this.becca.etapiTokens[this.etapiTokenId] = this;
  58. }
  59. init() {
  60. if (this.etapiTokenId) {
  61. this.becca.etapiTokens[this.etapiTokenId] = this;
  62. }
  63. }
  64. getPojo() {
  65. return {
  66. etapiTokenId: this.etapiTokenId,
  67. name: this.name,
  68. tokenHash: this.tokenHash,
  69. utcDateCreated: this.utcDateCreated,
  70. utcDateModified: this.utcDateModified,
  71. isDeleted: this.isDeleted
  72. }
  73. }
  74. beforeSaving() {
  75. this.utcDateModified = dateUtils.utcNowDateTime();
  76. super.beforeSaving();
  77. this.becca.etapiTokens[this.etapiTokenId] = this;
  78. }
  79. }
  80. module.exports = EtapiToken;
  81. </code></pre>
  82. </article>
  83. </section>
  84. </div>
  85. <nav>
  86. <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="Attribute.html">Attribute</a></li><li><a href="BackendScriptApi.html">BackendScriptApi</a></li><li><a href="Branch.html">Branch</a></li><li><a href="EtapiToken.html">EtapiToken</a></li><li><a href="Note.html">Note</a></li><li><a href="NoteRevision.html">NoteRevision</a></li><li><a href="Option.html">Option</a></li><li><a href="RecentNote.html">RecentNote</a></li></ul><h3><a href="global.html">Global</a></h3>
  87. </nav>
  88. <br class="clear">
  89. <footer>
  90. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a>
  91. </footer>
  92. <script> prettyPrint(); </script>
  93. <script src="scripts/linenumber.js"> </script>
  94. </body>
  95. </html>