index.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * The namespace's name is the same as the exported EggCookies,
  3. * so you can solely use CookieGetOptions and CookieSetOptions
  4. * when you use
  5. * `import {CookieGetOptions, CookieSetOptions} from 'egg-cookies'`.
  6. */
  7. declare namespace EggCookies {
  8. interface CookieGetOptions {
  9. /**
  10. * Whether to sign or not (The default value is true).
  11. */
  12. signed?: boolean;
  13. /**
  14. * Encrypt the cookie's value or not (The default value is false).
  15. */
  16. encrypt?: boolean;
  17. }
  18. interface CookieSetOptions {
  19. /**
  20. * The path for the cookie to be set in
  21. */
  22. path?: string;
  23. /**
  24. * The domain for the cookie
  25. */
  26. domain?: string;
  27. /**
  28. * Is overridable
  29. */
  30. overwrite?: boolean;
  31. /**
  32. * Is the same site
  33. */
  34. sameSite?: boolean | string;
  35. /**
  36. * Encrypt the cookie's value or not
  37. */
  38. encrypt?: boolean;
  39. /**
  40. * Max age for browsers
  41. */
  42. maxAge?: number;
  43. /**
  44. * Expire time
  45. */
  46. expires?: Date;
  47. /**
  48. * Is for http only
  49. */
  50. httpOnly?: boolean;
  51. /**
  52. * Encrypt the cookie's value or not
  53. */
  54. secure?: boolean;
  55. /**
  56. * Is it signed or not.
  57. */
  58. signed?: boolean;
  59. }
  60. class CookieError extends Error { }
  61. }
  62. declare class EggCookies {
  63. constructor(ctx?: any, keys?: any);
  64. /**
  65. * Get the Egg's cookies by name with optional options.
  66. * @param name The Egg's cookie's unique name.
  67. * @param opts Optional. The options for cookie's getting.
  68. * @returns The cookie's value according to the specific name.
  69. */
  70. get(name: string, opts?: EggCookies.CookieGetOptions): string;
  71. /**
  72. * Set the Egg's cookies by name with optional options.
  73. * @param name The Egg cookie's unique name.
  74. * @param value Optional. The Egg cookie's real value.
  75. * @param opts Optional. The options for cookie's setting.
  76. * @returns The current 'EggCookie' instance.
  77. */
  78. set(name: string, value?: string | null, opts?: EggCookies.CookieSetOptions): this;
  79. }
  80. export = EggCookies;