@api-client/core 0.3.1 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/build/browser.d.ts +1 -1
  2. package/build/index.d.ts +2 -2
  3. package/build/index.js.map +1 -1
  4. package/build/src/models/Backend.d.ts +22 -0
  5. package/build/src/runtime/store/StoreSdk.d.ts +192 -12
  6. package/build/src/runtime/store/StoreSdk.js +592 -53
  7. package/build/src/runtime/store/StoreSdk.js.map +1 -1
  8. package/package.json +3 -1
  9. package/src/data/DataReader.ts +11 -0
  10. package/src/data/DataUtils.ts +108 -0
  11. package/src/data/JmesparthReader.ts +26 -0
  12. package/src/data/Json2Xml.ts +190 -0
  13. package/src/data/JsonReader.ts +41 -0
  14. package/src/data/PayloadPointer.ts +48 -0
  15. package/src/data/RequestDataExtractor.ts +133 -0
  16. package/src/data/UrlEncodedReader.ts +20 -0
  17. package/src/data/XmlReader.ts +103 -0
  18. package/src/events/BaseEvents.ts +259 -0
  19. package/src/events/CustomEvent.ts +27 -0
  20. package/src/events/EventTypes.ts +19 -0
  21. package/src/events/Events.ts +19 -0
  22. package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
  23. package/src/events/authorization/AuthorizationEvents.ts +61 -0
  24. package/src/events/cookies/CookieEventTypes.ts +13 -0
  25. package/src/events/cookies/CookieEvents.ts +157 -0
  26. package/src/events/encryption/EncryptionEventTypes.ts +4 -0
  27. package/src/events/encryption/EncryptionEvents.ts +51 -0
  28. package/src/events/environment/EnvironmentEventTypes.ts +3 -0
  29. package/src/events/environment/EnvironmentEvents.ts +24 -0
  30. package/src/events/models/ClientCertificateEvents.ts +87 -0
  31. package/src/events/models/ModelEventTypes.ts +47 -0
  32. package/src/events/models/ModelEvents.ts +7 -0
  33. package/src/events/models/ProjectEvents.ts +331 -0
  34. package/src/events/process/ProcessEventTypes.ts +5 -0
  35. package/src/events/process/ProcessEvents.ts +76 -0
  36. package/src/events/readme.md +22 -0
  37. package/src/events/reporting/ReportingEventTypes.ts +3 -0
  38. package/src/events/reporting/ReportingEvents.ts +28 -0
  39. package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
  40. package/src/events/telemetry/TelemetryEvents.ts +156 -0
  41. package/src/lib/cookies/Cookie.ts +312 -0
  42. package/src/lib/cookies/Cookies.ts +326 -0
  43. package/src/lib/cookies/Utils.ts +168 -0
  44. package/src/lib/headers/Headers.ts +219 -0
  45. package/src/lib/logging/DefaultLogger.ts +19 -0
  46. package/src/lib/logging/DummyLogger.ts +21 -0
  47. package/src/lib/logging/Logger.ts +16 -0
  48. package/src/lib/transformers/PayloadSerializer.ts +332 -0
  49. package/src/lib/transformers/Utils.ts +18 -0
  50. package/src/lib/uuid.ts +40 -0
  51. package/src/mocking/LegacyInterfaces.ts +52 -0
  52. package/src/mocking/LegacyMock.ts +37 -0
  53. package/src/mocking/legacy/Authorization.ts +39 -0
  54. package/src/mocking/legacy/Certificates.ts +145 -0
  55. package/src/mocking/legacy/Cookies.ts +51 -0
  56. package/src/mocking/legacy/HostRules.ts +43 -0
  57. package/src/mocking/legacy/Http.ts +236 -0
  58. package/src/mocking/legacy/HttpResponse.ts +106 -0
  59. package/src/mocking/legacy/RestApi.ts +68 -0
  60. package/src/mocking/legacy/Urls.ts +44 -0
  61. package/src/mocking/legacy/Variables.ts +53 -0
  62. package/src/models/ArcResponse.ts +166 -0
  63. package/src/models/Authorization.ts +481 -0
  64. package/src/models/AuthorizationData.ts +60 -0
  65. package/src/models/Backend.ts +107 -0
  66. package/src/models/ClientCertificate.ts +68 -0
  67. package/src/models/Environment.ts +279 -0
  68. package/src/models/ErrorResponse.ts +101 -0
  69. package/src/models/HistoryIndex.ts +76 -0
  70. package/src/models/HistoryRequest.ts +28 -0
  71. package/src/models/HostRule.ts +163 -0
  72. package/src/models/HttpCookie.ts +285 -0
  73. package/src/models/HttpProject.ts +1294 -0
  74. package/src/models/HttpProjectListItem.ts +23 -0
  75. package/src/models/HttpRequest.ts +124 -0
  76. package/src/models/HttpResponse.ts +143 -0
  77. package/src/models/License.ts +113 -0
  78. package/src/models/ProjectDefinitionProperty.ts +40 -0
  79. package/src/models/ProjectFolder.ts +439 -0
  80. package/src/models/ProjectItem.ts +135 -0
  81. package/src/models/ProjectParent.ts +113 -0
  82. package/src/models/ProjectRequest.ts +277 -0
  83. package/src/models/ProjectSchema.ts +202 -0
  84. package/src/models/Property.ts +423 -0
  85. package/src/models/Provider.ts +98 -0
  86. package/src/models/README.md +20 -0
  87. package/src/models/Request.ts +452 -0
  88. package/src/models/RequestActions.ts +163 -0
  89. package/src/models/RequestAuthorization.ts +115 -0
  90. package/src/models/RequestConfig.ts +317 -0
  91. package/src/models/RequestLog.ts +159 -0
  92. package/src/models/RequestTime.ts +108 -0
  93. package/src/models/RequestUiMeta.ts +258 -0
  94. package/src/models/RequestsSize.ts +65 -0
  95. package/src/models/ResponseAuthorization.ts +104 -0
  96. package/src/models/ResponseRedirect.ts +158 -0
  97. package/src/models/RevisionInfo.ts +37 -0
  98. package/src/models/SentRequest.ts +125 -0
  99. package/src/models/SerializablePayload.ts +68 -0
  100. package/src/models/Server.ts +153 -0
  101. package/src/models/Thing.ts +110 -0
  102. package/src/models/Url.ts +90 -0
  103. package/src/models/User.ts +120 -0
  104. package/src/models/WebApi.ts +234 -0
  105. package/src/models/WebApiIndex.ts +122 -0
  106. package/src/models/Workspace.ts +182 -0
  107. package/src/models/actions/Action.ts +213 -0
  108. package/src/models/actions/ActionView.ts +40 -0
  109. package/src/models/actions/Condition.ts +207 -0
  110. package/src/models/actions/ConditionView.ts +42 -0
  111. package/src/models/actions/Enums.ts +29 -0
  112. package/src/models/actions/RunnableAction.ts +144 -0
  113. package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
  114. package/src/models/actions/runnable/Runnable.ts +9 -0
  115. package/src/models/actions/runnable/SetCookieAction.ts +216 -0
  116. package/src/models/actions/runnable/SetVariableAction.ts +81 -0
  117. package/src/models/legacy/DataExport.ts +172 -0
  118. package/src/models/legacy/Normalizer.ts +110 -0
  119. package/src/models/legacy/actions/Actions.ts +269 -0
  120. package/src/models/legacy/authorization/Authorization.ts +572 -0
  121. package/src/models/legacy/models/ApiTypes.ts +202 -0
  122. package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
  123. package/src/models/legacy/models/AuthData.ts +17 -0
  124. package/src/models/legacy/models/ClientCertificate.ts +95 -0
  125. package/src/models/legacy/models/Cookies.ts +52 -0
  126. package/src/models/legacy/models/HostRule.ts +35 -0
  127. package/src/models/legacy/models/RestApi.ts +49 -0
  128. package/src/models/legacy/models/UrlHistory.ts +37 -0
  129. package/src/models/legacy/models/Variable.ts +43 -0
  130. package/src/models/legacy/models/base.d.ts +95 -0
  131. package/src/models/legacy/request/ArcRequest.ts +405 -0
  132. package/src/models/legacy/request/ArcResponse.ts +177 -0
  133. package/src/models/legacy/request/HistoryData.ts +47 -0
  134. package/src/models/legacy/request/Legacy.ts +45 -0
  135. package/src/models/legacy/request/RequestBody.ts +87 -0
  136. package/src/models/transformers/ArcDexieTransformer.ts +323 -0
  137. package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
  138. package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
  139. package/src/models/transformers/ArcPouchTransformer.ts +184 -0
  140. package/src/models/transformers/BaseTransformer.ts +116 -0
  141. package/src/models/transformers/ImportUtils.ts +141 -0
  142. package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
  143. package/src/models/transformers/LegacyExportProcessor.ts +252 -0
  144. package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
  145. package/src/models/transformers/PostmanDataTransformer.ts +50 -0
  146. package/src/models/transformers/PostmanTransformer.ts +106 -0
  147. package/src/models/transformers/PostmanV21Transformer.ts +311 -0
  148. package/src/models/transformers/PostmanV2Transformer.ts +308 -0
  149. package/src/models/transformers/har.ts +865 -0
  150. package/src/runtime/actions/ActionRunner.ts +83 -0
  151. package/src/runtime/actions/ConditionRunner.ts +194 -0
  152. package/src/runtime/actions/RunnableCondition.ts +57 -0
  153. package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
  154. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
  155. package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
  156. package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
  157. package/src/runtime/http-engine/ArcEngine.ts +1064 -0
  158. package/src/runtime/http-engine/Errors.ts +13 -0
  159. package/src/runtime/http-engine/FormData.ts +85 -0
  160. package/src/runtime/http-engine/HttpEngine.ts +874 -0
  161. package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
  162. package/src/runtime/http-engine/NodeEngine.ts +787 -0
  163. package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
  164. package/src/runtime/http-engine/PayloadSupport.ts +84 -0
  165. package/src/runtime/http-engine/RequestUtils.ts +164 -0
  166. package/src/runtime/http-engine/ntlm/Des.ts +345 -0
  167. package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
  168. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
  169. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
  170. package/src/runtime/modules/BasicAuthCache.ts +133 -0
  171. package/src/runtime/modules/ExecutionResponse.ts +4 -0
  172. package/src/runtime/modules/ModulesRegistry.ts +136 -0
  173. package/src/runtime/modules/RequestAuthorization.ts +110 -0
  174. package/src/runtime/modules/RequestCookies.ts +145 -0
  175. package/src/runtime/node/ProjectRunner.ts +275 -0
  176. package/src/runtime/node/RequestFactory.ts +422 -0
  177. package/src/runtime/node/VariablesStore.ts +25 -0
  178. package/src/runtime/store/StoreSdk.ts +838 -0
  179. package/src/runtime/variables/Cache.ts +53 -0
  180. package/src/runtime/variables/EvalFunctions.ts +132 -0
  181. package/src/runtime/variables/ProjectVariables.ts +6 -0
  182. package/src/runtime/variables/VariablesProcessor.ts +543 -0
  183. package/src/runtime/variables/VariablesTokenizer.ts +55 -0
@@ -0,0 +1,28 @@
1
+ import { ReportingEventTypes } from './ReportingEventTypes.js';
2
+
3
+ export interface IReportingErrorDetail {
4
+ description: string;
5
+ error?: Error;
6
+ component?: string;
7
+ }
8
+
9
+ export class ReportingEvents {
10
+ /**
11
+ * Dispatches the general error event for UI logging purposes.
12
+ *
13
+ * @param target A node on which to dispatch the event
14
+ * @param description The error description
15
+ * @param error Optional original error object that has caused this event
16
+ * @param component Optional component name.
17
+ */
18
+ static error(target: EventTarget, description: string, error?: Error, component?: string): void {
19
+ const detail: IReportingErrorDetail = { error, description, component };
20
+ const e = new CustomEvent(ReportingEventTypes.error, {
21
+ bubbles: true,
22
+ composed: true,
23
+ cancelable: true,
24
+ detail,
25
+ });
26
+ target.dispatchEvent(e);
27
+ }
28
+ }
@@ -0,0 +1,10 @@
1
+ export const TelemetryEventTypes = Object.freeze({
2
+ view: 'telemetryscreenview',
3
+ event: 'telemetryevent',
4
+ exception: 'telemetryexception',
5
+ social: 'telemetrysocial',
6
+ timing: 'telemetrytiming',
7
+ State: Object.freeze({
8
+ set: 'telemetrystateset',
9
+ }),
10
+ });
@@ -0,0 +1,156 @@
1
+ import { TelemetryEventTypes } from './TelemetryEventTypes.js';
2
+
3
+ export interface ITelemetryCustomMetric {
4
+ index: number;
5
+ value: number;
6
+ }
7
+ export interface ITelemetryCustomValue {
8
+ index: number;
9
+ value: string;
10
+ }
11
+
12
+ export interface ITelemetryDetail {
13
+ customMetrics?: ITelemetryCustomMetric[];
14
+ customDimensions?: ITelemetryCustomValue[];
15
+ }
16
+
17
+ export interface ITelemetryScreenViewDetail extends ITelemetryDetail {
18
+ screenName: string;
19
+ }
20
+
21
+ export interface ITelemetryEventDetail extends ITelemetryDetail {
22
+ category: string;
23
+ action: string;
24
+ label?: string;
25
+ value?: number;
26
+ }
27
+
28
+ export interface ITelemetryExceptionDetail extends ITelemetryDetail {
29
+ description: string;
30
+ fatal?: boolean;
31
+ }
32
+ export interface ITelemetrySocialDetail extends ITelemetryDetail {
33
+ network: string;
34
+ action: string;
35
+ target: string;
36
+ }
37
+ export interface ITelemetryTimingDetail extends ITelemetryDetail {
38
+ category: string;
39
+ variable: string;
40
+ value: number;
41
+ label?: string;
42
+ }
43
+
44
+ export class TelemetryEvents {
45
+ /**
46
+ * Sends application screen view event
47
+ * @param target A node on which to dispatch the event
48
+ * @param screenName The screen name
49
+ * @param info Analytics base configuration
50
+ */
51
+ static view(target: EventTarget, screenName: string, info: ITelemetryDetail = {}): void {
52
+ const detail: ITelemetryScreenViewDetail = {
53
+ ...info, screenName,
54
+ };
55
+ const e = new CustomEvent(TelemetryEventTypes.view, {
56
+ bubbles: true,
57
+ composed: true,
58
+ cancelable: true,
59
+ detail,
60
+ });
61
+ target.dispatchEvent(e);
62
+ }
63
+
64
+ /**
65
+ * Sends a Google Analytics event information
66
+ * @param target A node on which to dispatch the event
67
+ * @param detail The event configuration
68
+ */
69
+ static event(target: EventTarget, detail: ITelemetryEventDetail): void {
70
+ const e = new CustomEvent(TelemetryEventTypes.event, {
71
+ bubbles: true,
72
+ composed: true,
73
+ cancelable: true,
74
+ detail,
75
+ });
76
+ target.dispatchEvent(e);
77
+ }
78
+
79
+ /**
80
+ * Sends a Google Analytics exception information
81
+ * @param target A node on which to dispatch the event
82
+ * @param description The exception description
83
+ * @param fatal Whether the exception was fatal to the application
84
+ * @param info Analytics base configuration
85
+ */
86
+ static exception(target: EventTarget, description: string, fatal?: boolean, info: ITelemetryDetail = {}): void {
87
+ const detail: ITelemetryExceptionDetail = { ...info, description, fatal };
88
+ const e = new CustomEvent(TelemetryEventTypes.exception, {
89
+ bubbles: true,
90
+ composed: true,
91
+ cancelable: true,
92
+ detail,
93
+ });
94
+ target.dispatchEvent(e);
95
+ }
96
+
97
+ /**
98
+ * Sends a Google Analytics social share information
99
+ * @param target A node on which to dispatch the event
100
+ * @param network The network where the shared content is shared
101
+ * @param action The share action, eg. 'Share'
102
+ * @param url The share url
103
+ * @param info Analytics base configuration
104
+ */
105
+ static social(target: EventTarget, network: string, action: string, url: string, info: ITelemetryDetail = {}): void {
106
+ const detail: ITelemetrySocialDetail = { ...info, network, action, target: url };
107
+ const e = new CustomEvent(TelemetryEventTypes.social, {
108
+ bubbles: true,
109
+ composed: true,
110
+ cancelable: true,
111
+ detail,
112
+ });
113
+ target.dispatchEvent(e);
114
+ }
115
+
116
+ /**
117
+ * Sends a Google Analytics application timing information
118
+ * @param target A node on which to dispatch the event
119
+ * @param category The timing category
120
+ * @param variable The timing variable
121
+ * @param value The timing value
122
+ * @param label The timing label
123
+ * @param info Analytics base configuration
124
+ */
125
+ static timing(target: EventTarget, category: string, variable: string, value: number, label?: string, info: ITelemetryDetail = {}): void {
126
+ const detail: ITelemetryTimingDetail = { ...info, category, variable, value, label };
127
+ const e = new CustomEvent(TelemetryEventTypes.timing, {
128
+ bubbles: true,
129
+ composed: true,
130
+ cancelable: true,
131
+ detail,
132
+ });
133
+ target.dispatchEvent(e);
134
+ }
135
+
136
+ static get State(): typeof StateEvents {
137
+ return StateEvents;
138
+ }
139
+ }
140
+
141
+ class StateEvents {
142
+ /**
143
+ * Dispatched when the user made the initial telemetry settings.
144
+ * The application can check for the sate of the telemetry in the corresponding configuration.
145
+ *
146
+ * @param target The node on which to dispatch the event.
147
+ */
148
+ static set(target: EventTarget): void {
149
+ const e = new Event(TelemetryEventTypes.State.set, {
150
+ composed: true,
151
+ cancelable: true,
152
+ bubbles: true,
153
+ });
154
+ target.dispatchEvent(e);
155
+ }
156
+ }
@@ -0,0 +1,312 @@
1
+ import { CookieSameSiteType } from '../../models/HttpCookie.js';
2
+
3
+ /**
4
+ * Cookie creation options.
5
+ */
6
+ export interface CookieOptions {
7
+ 'max-age'?: number;
8
+ /**
9
+ * When the cookie expires.
10
+ * Note that this value is parsed to a timestamp in the Cookie class.
11
+ */
12
+ expires?: Date | number | string;
13
+ /**
14
+ * A string representing the domain the cookie belongs to
15
+ * (e.g. "www.google.com", "example.com")
16
+ */
17
+ domain?: string;
18
+ /**
19
+ * Cookie path
20
+ */
21
+ path?: string;
22
+ /**
23
+ * A boolean, `true` if the cookie is marked as secure
24
+ * (i.e. its scope is limited to secure channels, typically HTTPS),
25
+ * or `false` otherwise.
26
+ */
27
+ secure?: boolean;
28
+ /**
29
+ * A boolean, `true` if the cookie is marked as HttpOnly
30
+ * (i.e. the cookie is inaccessible to client-side scripts),
31
+ * or `false` otherwise.
32
+ */
33
+ httpOnly?: boolean;
34
+ /**
35
+ * A boolean, `true` if the cookie is a `host-only` cookie
36
+ * (i.e. the request's host must exactly match the domain of the cookie),
37
+ * or `false` otherwise.
38
+ */
39
+ hostOnly?: boolean;
40
+ /**
41
+ * The SameSite attribute of the Set-Cookie HTTP response header allows you to declare if your cookie should be restricted to a first-party or same-site context.
42
+ */
43
+ sameSite?: CookieSameSiteType;
44
+ }
45
+
46
+ /* eslint-disable no-control-regex */
47
+ const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
48
+
49
+ /**
50
+ * A Cookie object.
51
+ * It is based on https://github.com/pillarjs/cookies/blob/master/lib/cookies.js
52
+ */
53
+ export class Cookie {
54
+ protected _maxAge?: number;
55
+ protected _expires: number;
56
+ protected _domain?: string;
57
+ name: string;
58
+ value: string;
59
+ created: number;
60
+ lastAccess: number;
61
+ persistent?: boolean;
62
+ hostOnly?: boolean;
63
+ path?: string;
64
+ secure?: boolean;
65
+ httpOnly?: boolean;
66
+ sameSite?: CookieSameSiteType;
67
+
68
+ /**
69
+ * Constructs a new cookie.
70
+ *
71
+ * @param name Cookie name
72
+ * @param value Cookie value
73
+ * @param opts Additional cookie attributes.
74
+ */
75
+ constructor(name: string, value = '', opts: CookieOptions = {}) {
76
+ if (!fieldContentRegExp.test(name)) {
77
+ throw new TypeError('Argument `name` is invalid');
78
+ }
79
+ if (value && !fieldContentRegExp.test(value)) {
80
+ throw new TypeError('Argument `value` is invalid');
81
+ }
82
+ if (opts.path && !fieldContentRegExp.test(opts.path)) {
83
+ throw new TypeError('Option `path` is invalid');
84
+ }
85
+ if (opts.domain && !fieldContentRegExp.test(opts.domain)) {
86
+ throw new TypeError('Option `domain` is invalid');
87
+ }
88
+ this._expires = 0;
89
+ this._domain = undefined;
90
+ this._maxAge = undefined;
91
+ this.name = name;
92
+ this.value = value;
93
+ this.created = Date.now();
94
+ this.lastAccess = this.created;
95
+
96
+ if ('max-age' in opts) {
97
+ this.maxAge = opts['max-age'];
98
+ } else if (typeof opts.expires !== 'undefined') {
99
+ this.setExpires(opts.expires);
100
+ } else {
101
+ this.persistent = false;
102
+ // see http://stackoverflow.com/a/11526569/1127848
103
+ this._expires = new Date(8640000000000000).getTime();
104
+ }
105
+ if ('hostOnly' in opts) {
106
+ this.hostOnly = opts.hostOnly;
107
+ }
108
+ if ('domain' in opts) {
109
+ this.domain = opts.domain;
110
+ } else {
111
+ this.hostOnly = false;
112
+ }
113
+ if ('path' in opts) {
114
+ this.path = opts.path;
115
+ }
116
+ if ('secure' in opts) {
117
+ this.secure = opts.secure;
118
+ }
119
+ if ('httpOnly' in opts) {
120
+ this.httpOnly = opts.httpOnly;
121
+ }
122
+ if ('sameSite' in opts) {
123
+ this.sameSite = opts.sameSite;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * @param max The max age value
129
+ */
130
+ set maxAge(max: number | undefined) {
131
+ const typedMax = Number(max);
132
+ if (Number.isNaN(typedMax)) {
133
+ return;
134
+ }
135
+ this._maxAge = typedMax;
136
+ if (typedMax <= 0) {
137
+ // see http://stackoverflow.com/a/11526569/1127848
138
+ // and https://tools.ietf.org/html/rfc6265#section-5.2.2
139
+ this._expires = new Date(-8640000000000000).getTime();
140
+ } else {
141
+ let now = Date.now();
142
+ now += typedMax * 1000;
143
+ this._expires = now;
144
+ }
145
+ this.persistent = true;
146
+ }
147
+
148
+ /**
149
+ * @return Returns a value of maxAge property
150
+ */
151
+ get maxAge(): number | undefined {
152
+ return this._maxAge;
153
+ }
154
+
155
+ get ['max-age'](): number | undefined {
156
+ return this.maxAge;
157
+ }
158
+
159
+ set ['max-age'](value: number | undefined) {
160
+ this.maxAge = value;
161
+ }
162
+
163
+ /**
164
+ * @param expires The value for expires
165
+ */
166
+ set expires(expires: number | Date | string) {
167
+ const any = expires as unknown;
168
+ if ((expires && typeof any === 'string') || any instanceof Date) {
169
+ this.setExpires(any);
170
+ return;
171
+ }
172
+ this._expires = expires as number;
173
+ this.persistent = true;
174
+ }
175
+
176
+ /**
177
+ * @return the current expires value
178
+ */
179
+ get expires(): number {
180
+ return this._expires;
181
+ }
182
+
183
+ /**
184
+ * @param domain The cookie domain
185
+ */
186
+ set domain(domain: string | undefined) {
187
+ this._domain = domain;
188
+ if (!domain) {
189
+ this.hostOnly = false;
190
+ } else {
191
+ this.hostOnly = true;
192
+ }
193
+ }
194
+
195
+ /**
196
+ * @return The cookie domain
197
+ */
198
+ get domain(): string | undefined {
199
+ return this._domain;
200
+ }
201
+
202
+ get samesite(): CookieSameSiteType | undefined {
203
+ return this.sameSite;
204
+ }
205
+
206
+ set samesite(value: CookieSameSiteType | undefined) {
207
+ this.sameSite = value;
208
+ }
209
+
210
+ get httponly(): boolean | undefined {
211
+ return this.httpOnly;
212
+ }
213
+
214
+ set httponly(value: boolean | undefined) {
215
+ this.httpOnly = value;
216
+ }
217
+
218
+ get hostonly(): boolean | undefined {
219
+ return this.hostOnly;
220
+ }
221
+
222
+ set hostonly(value: boolean | undefined) {
223
+ this.hostOnly = value;
224
+ }
225
+
226
+ /**
227
+ * @return Cookie's `name=value` string.
228
+ */
229
+ toString(): string {
230
+ const { name, value } = this;
231
+ return `${name}=${value}`;
232
+ }
233
+
234
+ /**
235
+ * Returns a Cookie as a HTTP header string.
236
+ * @return Cookie string as a HTTP header value
237
+ */
238
+ toHeader(): string {
239
+ let header = this.toString();
240
+ let expires;
241
+ if (this._expires) {
242
+ expires = new Date(this._expires);
243
+ if (expires.toString() === 'Invalid Date') {
244
+ expires = new Date(0);
245
+ }
246
+ }
247
+ if (expires) {
248
+ header += `; expires=${expires.toUTCString()}`;
249
+ }
250
+ const { path, domain, httpOnly, sameSite, secure } = this;
251
+ if (path) {
252
+ header += `; path=${path}`;
253
+ }
254
+ if (domain) {
255
+ header += `; domain=${domain}`;
256
+ }
257
+ if (httpOnly) {
258
+ header += `; httpOnly=${httpOnly}`;
259
+ }
260
+ if (sameSite) {
261
+ header += `; SameSite=${sameSite}`;
262
+ }
263
+ if (secure) {
264
+ header += `; Secure`;
265
+ }
266
+ return header;
267
+ }
268
+
269
+ /**
270
+ * Override toJSON behaviour so it will eliminate
271
+ * all _* properties and replace it with a proper ones.
272
+ *
273
+ * @return {object}
274
+ */
275
+ toJSON(): Record<string, string> {
276
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
+ const copy: any = {};
278
+ const keys: (keyof Cookie)[] = Object.keys(this) as (keyof Cookie)[];
279
+ keys.forEach((key) => {
280
+ if (key.indexOf('_') === 0) {
281
+ const realKey = key.substring(1);
282
+ copy[realKey] = this[key];
283
+ } else {
284
+ copy[key] = this[key];
285
+ }
286
+ });
287
+ return copy;
288
+ }
289
+
290
+ /**
291
+ * Sets value for `expirers` propr from other types.
292
+ * @param expires The value for `expires`
293
+ */
294
+ setExpires(expires: Date | string | number): void {
295
+ let value: number;
296
+ if (expires instanceof Date) {
297
+ value = expires.getTime();
298
+ } else if (typeof expires === 'string') {
299
+ const tmp = new Date(expires);
300
+ if (tmp.toString() === 'Invalid Date') {
301
+ value = 0;
302
+ } else {
303
+ value = tmp.getTime();
304
+ }
305
+ } else if (typeof expires === 'number') {
306
+ value = expires;
307
+ } else {
308
+ value = 0;
309
+ }
310
+ this.expires = value;
311
+ }
312
+ }