@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.
- package/build/browser.d.ts +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js.map +1 -1
- package/build/src/models/Backend.d.ts +22 -0
- package/build/src/runtime/store/StoreSdk.d.ts +192 -12
- package/build/src/runtime/store/StoreSdk.js +592 -53
- package/build/src/runtime/store/StoreSdk.js.map +1 -1
- package/package.json +3 -1
- package/src/data/DataReader.ts +11 -0
- package/src/data/DataUtils.ts +108 -0
- package/src/data/JmesparthReader.ts +26 -0
- package/src/data/Json2Xml.ts +190 -0
- package/src/data/JsonReader.ts +41 -0
- package/src/data/PayloadPointer.ts +48 -0
- package/src/data/RequestDataExtractor.ts +133 -0
- package/src/data/UrlEncodedReader.ts +20 -0
- package/src/data/XmlReader.ts +103 -0
- package/src/events/BaseEvents.ts +259 -0
- package/src/events/CustomEvent.ts +27 -0
- package/src/events/EventTypes.ts +19 -0
- package/src/events/Events.ts +19 -0
- package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
- package/src/events/authorization/AuthorizationEvents.ts +61 -0
- package/src/events/cookies/CookieEventTypes.ts +13 -0
- package/src/events/cookies/CookieEvents.ts +157 -0
- package/src/events/encryption/EncryptionEventTypes.ts +4 -0
- package/src/events/encryption/EncryptionEvents.ts +51 -0
- package/src/events/environment/EnvironmentEventTypes.ts +3 -0
- package/src/events/environment/EnvironmentEvents.ts +24 -0
- package/src/events/models/ClientCertificateEvents.ts +87 -0
- package/src/events/models/ModelEventTypes.ts +47 -0
- package/src/events/models/ModelEvents.ts +7 -0
- package/src/events/models/ProjectEvents.ts +331 -0
- package/src/events/process/ProcessEventTypes.ts +5 -0
- package/src/events/process/ProcessEvents.ts +76 -0
- package/src/events/readme.md +22 -0
- package/src/events/reporting/ReportingEventTypes.ts +3 -0
- package/src/events/reporting/ReportingEvents.ts +28 -0
- package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
- package/src/events/telemetry/TelemetryEvents.ts +156 -0
- package/src/lib/cookies/Cookie.ts +312 -0
- package/src/lib/cookies/Cookies.ts +326 -0
- package/src/lib/cookies/Utils.ts +168 -0
- package/src/lib/headers/Headers.ts +219 -0
- package/src/lib/logging/DefaultLogger.ts +19 -0
- package/src/lib/logging/DummyLogger.ts +21 -0
- package/src/lib/logging/Logger.ts +16 -0
- package/src/lib/transformers/PayloadSerializer.ts +332 -0
- package/src/lib/transformers/Utils.ts +18 -0
- package/src/lib/uuid.ts +40 -0
- package/src/mocking/LegacyInterfaces.ts +52 -0
- package/src/mocking/LegacyMock.ts +37 -0
- package/src/mocking/legacy/Authorization.ts +39 -0
- package/src/mocking/legacy/Certificates.ts +145 -0
- package/src/mocking/legacy/Cookies.ts +51 -0
- package/src/mocking/legacy/HostRules.ts +43 -0
- package/src/mocking/legacy/Http.ts +236 -0
- package/src/mocking/legacy/HttpResponse.ts +106 -0
- package/src/mocking/legacy/RestApi.ts +68 -0
- package/src/mocking/legacy/Urls.ts +44 -0
- package/src/mocking/legacy/Variables.ts +53 -0
- package/src/models/ArcResponse.ts +166 -0
- package/src/models/Authorization.ts +481 -0
- package/src/models/AuthorizationData.ts +60 -0
- package/src/models/Backend.ts +107 -0
- package/src/models/ClientCertificate.ts +68 -0
- package/src/models/Environment.ts +279 -0
- package/src/models/ErrorResponse.ts +101 -0
- package/src/models/HistoryIndex.ts +76 -0
- package/src/models/HistoryRequest.ts +28 -0
- package/src/models/HostRule.ts +163 -0
- package/src/models/HttpCookie.ts +285 -0
- package/src/models/HttpProject.ts +1294 -0
- package/src/models/HttpProjectListItem.ts +23 -0
- package/src/models/HttpRequest.ts +124 -0
- package/src/models/HttpResponse.ts +143 -0
- package/src/models/License.ts +113 -0
- package/src/models/ProjectDefinitionProperty.ts +40 -0
- package/src/models/ProjectFolder.ts +439 -0
- package/src/models/ProjectItem.ts +135 -0
- package/src/models/ProjectParent.ts +113 -0
- package/src/models/ProjectRequest.ts +277 -0
- package/src/models/ProjectSchema.ts +202 -0
- package/src/models/Property.ts +423 -0
- package/src/models/Provider.ts +98 -0
- package/src/models/README.md +20 -0
- package/src/models/Request.ts +452 -0
- package/src/models/RequestActions.ts +163 -0
- package/src/models/RequestAuthorization.ts +115 -0
- package/src/models/RequestConfig.ts +317 -0
- package/src/models/RequestLog.ts +159 -0
- package/src/models/RequestTime.ts +108 -0
- package/src/models/RequestUiMeta.ts +258 -0
- package/src/models/RequestsSize.ts +65 -0
- package/src/models/ResponseAuthorization.ts +104 -0
- package/src/models/ResponseRedirect.ts +158 -0
- package/src/models/RevisionInfo.ts +37 -0
- package/src/models/SentRequest.ts +125 -0
- package/src/models/SerializablePayload.ts +68 -0
- package/src/models/Server.ts +153 -0
- package/src/models/Thing.ts +110 -0
- package/src/models/Url.ts +90 -0
- package/src/models/User.ts +120 -0
- package/src/models/WebApi.ts +234 -0
- package/src/models/WebApiIndex.ts +122 -0
- package/src/models/Workspace.ts +182 -0
- package/src/models/actions/Action.ts +213 -0
- package/src/models/actions/ActionView.ts +40 -0
- package/src/models/actions/Condition.ts +207 -0
- package/src/models/actions/ConditionView.ts +42 -0
- package/src/models/actions/Enums.ts +29 -0
- package/src/models/actions/RunnableAction.ts +144 -0
- package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
- package/src/models/actions/runnable/Runnable.ts +9 -0
- package/src/models/actions/runnable/SetCookieAction.ts +216 -0
- package/src/models/actions/runnable/SetVariableAction.ts +81 -0
- package/src/models/legacy/DataExport.ts +172 -0
- package/src/models/legacy/Normalizer.ts +110 -0
- package/src/models/legacy/actions/Actions.ts +269 -0
- package/src/models/legacy/authorization/Authorization.ts +572 -0
- package/src/models/legacy/models/ApiTypes.ts +202 -0
- package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
- package/src/models/legacy/models/AuthData.ts +17 -0
- package/src/models/legacy/models/ClientCertificate.ts +95 -0
- package/src/models/legacy/models/Cookies.ts +52 -0
- package/src/models/legacy/models/HostRule.ts +35 -0
- package/src/models/legacy/models/RestApi.ts +49 -0
- package/src/models/legacy/models/UrlHistory.ts +37 -0
- package/src/models/legacy/models/Variable.ts +43 -0
- package/src/models/legacy/models/base.d.ts +95 -0
- package/src/models/legacy/request/ArcRequest.ts +405 -0
- package/src/models/legacy/request/ArcResponse.ts +177 -0
- package/src/models/legacy/request/HistoryData.ts +47 -0
- package/src/models/legacy/request/Legacy.ts +45 -0
- package/src/models/legacy/request/RequestBody.ts +87 -0
- package/src/models/transformers/ArcDexieTransformer.ts +323 -0
- package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
- package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
- package/src/models/transformers/ArcPouchTransformer.ts +184 -0
- package/src/models/transformers/BaseTransformer.ts +116 -0
- package/src/models/transformers/ImportUtils.ts +141 -0
- package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
- package/src/models/transformers/LegacyExportProcessor.ts +252 -0
- package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
- package/src/models/transformers/PostmanDataTransformer.ts +50 -0
- package/src/models/transformers/PostmanTransformer.ts +106 -0
- package/src/models/transformers/PostmanV21Transformer.ts +311 -0
- package/src/models/transformers/PostmanV2Transformer.ts +308 -0
- package/src/models/transformers/har.ts +865 -0
- package/src/runtime/actions/ActionRunner.ts +83 -0
- package/src/runtime/actions/ConditionRunner.ts +194 -0
- package/src/runtime/actions/RunnableCondition.ts +57 -0
- package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
- package/src/runtime/http-engine/ArcEngine.ts +1064 -0
- package/src/runtime/http-engine/Errors.ts +13 -0
- package/src/runtime/http-engine/FormData.ts +85 -0
- package/src/runtime/http-engine/HttpEngine.ts +874 -0
- package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
- package/src/runtime/http-engine/NodeEngine.ts +787 -0
- package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
- package/src/runtime/http-engine/PayloadSupport.ts +84 -0
- package/src/runtime/http-engine/RequestUtils.ts +164 -0
- package/src/runtime/http-engine/ntlm/Des.ts +345 -0
- package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
- package/src/runtime/modules/BasicAuthCache.ts +133 -0
- package/src/runtime/modules/ExecutionResponse.ts +4 -0
- package/src/runtime/modules/ModulesRegistry.ts +136 -0
- package/src/runtime/modules/RequestAuthorization.ts +110 -0
- package/src/runtime/modules/RequestCookies.ts +145 -0
- package/src/runtime/node/ProjectRunner.ts +275 -0
- package/src/runtime/node/RequestFactory.ts +422 -0
- package/src/runtime/node/VariablesStore.ts +25 -0
- package/src/runtime/store/StoreSdk.ts +838 -0
- package/src/runtime/variables/Cache.ts +53 -0
- package/src/runtime/variables/EvalFunctions.ts +132 -0
- package/src/runtime/variables/ProjectVariables.ts +6 -0
- package/src/runtime/variables/VariablesProcessor.ts +543 -0
- package/src/runtime/variables/VariablesTokenizer.ts +55 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IRequest, Request } from './Request.js';
|
|
2
|
+
|
|
3
|
+
export const Kind = 'ARC#HistoryRequest';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A class that specializes in processing ARC history request object.
|
|
7
|
+
*/
|
|
8
|
+
export class HistoryRequest extends Request {
|
|
9
|
+
kind = Kind;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generates an id for a history object
|
|
13
|
+
*/
|
|
14
|
+
generateId(): string {
|
|
15
|
+
const { method='', url='' } = this.expects;
|
|
16
|
+
const d = new Date();
|
|
17
|
+
d.setHours(0, 0, 0, 0);
|
|
18
|
+
const time = d.getTime();
|
|
19
|
+
const encUrl = encodeURIComponent(url);
|
|
20
|
+
return `${time}/${encUrl}/${method}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toJSON(): IRequest {
|
|
24
|
+
const result = super.toJSON();
|
|
25
|
+
result.kind = Kind;
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
export const Kind = 'ARC#HostRule';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ARC host rule definition.
|
|
5
|
+
*/
|
|
6
|
+
export interface IHostRule {
|
|
7
|
+
kind?: typeof Kind;
|
|
8
|
+
/**
|
|
9
|
+
* The from rule (may contain asterisks)
|
|
10
|
+
*/
|
|
11
|
+
from: string;
|
|
12
|
+
/**
|
|
13
|
+
* replacement value
|
|
14
|
+
*/
|
|
15
|
+
to: string;
|
|
16
|
+
/**
|
|
17
|
+
* if false the rule is ignored
|
|
18
|
+
*/
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* optional rule description
|
|
22
|
+
*/
|
|
23
|
+
comment?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class HostRule {
|
|
27
|
+
kind = Kind;
|
|
28
|
+
/**
|
|
29
|
+
* The from rule (may contain asterisks)
|
|
30
|
+
*/
|
|
31
|
+
from = '';
|
|
32
|
+
/**
|
|
33
|
+
* replacement value
|
|
34
|
+
*/
|
|
35
|
+
to = '';
|
|
36
|
+
/**
|
|
37
|
+
* if false the rule is ignored
|
|
38
|
+
*/
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* optional rule description
|
|
42
|
+
*/
|
|
43
|
+
comment?: string;
|
|
44
|
+
|
|
45
|
+
static fromValues(from: string, to: string ): HostRule {
|
|
46
|
+
const result = new HostRule({
|
|
47
|
+
kind: Kind,
|
|
48
|
+
from,
|
|
49
|
+
to,
|
|
50
|
+
enabled: true,
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param input The thing definition used to restore the state.
|
|
57
|
+
*/
|
|
58
|
+
constructor(input?: string | IHostRule) {
|
|
59
|
+
let init: IHostRule;
|
|
60
|
+
if (typeof input === 'string') {
|
|
61
|
+
init = JSON.parse(input);
|
|
62
|
+
} else if (typeof input === 'object') {
|
|
63
|
+
init = input;
|
|
64
|
+
} else {
|
|
65
|
+
init = {
|
|
66
|
+
kind: Kind,
|
|
67
|
+
from: '',
|
|
68
|
+
to: '',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
this.new(init);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new thing clearing anything that is so far defined.
|
|
76
|
+
*
|
|
77
|
+
* Note, this throws an error when the server is not an ARC thing.
|
|
78
|
+
*/
|
|
79
|
+
new(init: IHostRule): void {
|
|
80
|
+
if (!HostRule.isHostRule(init)) {
|
|
81
|
+
throw new Error(`Not an ARC HostRule.`);
|
|
82
|
+
}
|
|
83
|
+
const { from='', to='', enabled, comment } = init;
|
|
84
|
+
this.kind = Kind;
|
|
85
|
+
this.from = from;
|
|
86
|
+
this.to = to;
|
|
87
|
+
this.enabled = enabled;
|
|
88
|
+
this.comment = comment;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Checks whether the input is a definition of a host rule.
|
|
93
|
+
*/
|
|
94
|
+
static isHostRule(input: unknown): boolean {
|
|
95
|
+
const typed = input as IHostRule;
|
|
96
|
+
if (input && typed.kind && typed.kind === Kind) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
toJSON(): IHostRule {
|
|
103
|
+
const result: IHostRule = {
|
|
104
|
+
kind: Kind,
|
|
105
|
+
from : this.from,
|
|
106
|
+
to : this.to,
|
|
107
|
+
};
|
|
108
|
+
if (typeof this.enabled === 'boolean') {
|
|
109
|
+
result.enabled = this.enabled;
|
|
110
|
+
}
|
|
111
|
+
if (this.comment) {
|
|
112
|
+
result.comment = this.comment;
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Applies `hosts` rules to the URL.
|
|
119
|
+
*
|
|
120
|
+
* @param value An URL to apply the rules to
|
|
121
|
+
* @param rules List of host rules. It is a list of objects containing `from` and `to` properties.
|
|
122
|
+
* @return Evaluated URL with hosts rules.
|
|
123
|
+
*/
|
|
124
|
+
static applyHosts(value: string, rules: HostRule[]): string {
|
|
125
|
+
if (!rules || !rules.length) {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
for (let i = 0; i < rules.length; i++) {
|
|
129
|
+
const rule = rules[i];
|
|
130
|
+
const result = HostRule.evaluateRule(value, rule);
|
|
131
|
+
if (result) {
|
|
132
|
+
value = result;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Evaluates hosts rule and applies it to the `url`.
|
|
140
|
+
* @param {string} url The URL to evaluate
|
|
141
|
+
* @param {HostRule} rule ARC rule definition
|
|
142
|
+
* @return {string} Processed url.
|
|
143
|
+
*/
|
|
144
|
+
static evaluateRule(url: string, rule: HostRule): string | undefined {
|
|
145
|
+
if (!rule || !rule.from || !rule.to) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const re = HostRule.createRuleRe(rule.from);
|
|
149
|
+
if (!re.test(url)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
return url.replace(re, rule.to);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @param input Rule body
|
|
157
|
+
* @return Regular expression for the rule.
|
|
158
|
+
*/
|
|
159
|
+
static createRuleRe(input: string): RegExp {
|
|
160
|
+
input = input.replace(/\*/g, '(.*)');
|
|
161
|
+
return new RegExp(input, 'gi');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { ARCCookie as LegacyARCCookie } from './legacy/models/Cookies.js';
|
|
2
|
+
import { Cookie as ParserCookie } from '../lib/cookies/Cookie.js';
|
|
3
|
+
|
|
4
|
+
export type CookieSameSiteType = 'unspecified' | 'no_restriction' | 'lax' | 'strict';
|
|
5
|
+
export type CookieChangeReason = 'explicit' | 'overwrite' | 'expired' | 'evicted' | 'expired-overwrite';
|
|
6
|
+
|
|
7
|
+
export interface IHttpCookieChangeRecord {
|
|
8
|
+
/**
|
|
9
|
+
* The cookie that was changed.
|
|
10
|
+
*/
|
|
11
|
+
cookie: IHttpCookie;
|
|
12
|
+
/**
|
|
13
|
+
* The cause of the change with one of the following values:
|
|
14
|
+
* - `explicit` - The cookie was changed directly by a consumer's action.
|
|
15
|
+
* - `overwrite` - The cookie was automatically removed due to an insert operation that overwrote it.
|
|
16
|
+
* - `expired` - The cookie was automatically removed as it expired.
|
|
17
|
+
* - `evicted` - The cookie was automatically evicted during garbage collection.
|
|
18
|
+
* - `expired-overwrite` - The cookie was overwritten with an already-expired expiration date.
|
|
19
|
+
*/
|
|
20
|
+
cause: CookieChangeReason;
|
|
21
|
+
/**
|
|
22
|
+
* `true` if the cookie was removed, `false` otherwise.
|
|
23
|
+
*/
|
|
24
|
+
removed: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IHttpCookie {
|
|
28
|
+
// https://www.electronjs.org/docs/latest/api/structures/cookie
|
|
29
|
+
/**
|
|
30
|
+
* The name of the cookie.
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* The value of the cookie.
|
|
35
|
+
*/
|
|
36
|
+
value: string;
|
|
37
|
+
/**
|
|
38
|
+
* The domain of the cookie; this will be normalized with a preceding dot so that
|
|
39
|
+
* it's also valid for subdomains.
|
|
40
|
+
*/
|
|
41
|
+
domain?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the cookie is a host-only cookie; this will only be `true` if no domain
|
|
44
|
+
* was passed.
|
|
45
|
+
*/
|
|
46
|
+
hostOnly?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The path of the cookie.
|
|
49
|
+
*/
|
|
50
|
+
path?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the cookie is marked as secure.
|
|
53
|
+
*/
|
|
54
|
+
secure?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the cookie is marked as HTTP only.
|
|
57
|
+
*/
|
|
58
|
+
httpOnly?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the cookie is a session cookie or a persistent cookie with an expiration
|
|
61
|
+
* date.
|
|
62
|
+
*/
|
|
63
|
+
session?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The expiration date of the cookie as the number of seconds since the UNIX epoch.
|
|
66
|
+
* Not provided for session cookies.
|
|
67
|
+
*/
|
|
68
|
+
expirationDate?: number;
|
|
69
|
+
/**
|
|
70
|
+
* The Same Site policy applied to this cookie. Can be `unspecified`, `no_restriction`, `lax` or `strict`.
|
|
71
|
+
* @default unspecified
|
|
72
|
+
*/
|
|
73
|
+
sameSite: CookieSameSiteType;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class HttpCookie {
|
|
77
|
+
/**
|
|
78
|
+
* The name of the cookie.
|
|
79
|
+
*/
|
|
80
|
+
name = '';
|
|
81
|
+
/**
|
|
82
|
+
* The value of the cookie.
|
|
83
|
+
*/
|
|
84
|
+
value = '';
|
|
85
|
+
/**
|
|
86
|
+
* The domain of the cookie; this will be normalized with a preceding dot so that
|
|
87
|
+
* it's also valid for subdomains.
|
|
88
|
+
*/
|
|
89
|
+
domain?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the cookie is a host-only cookie; this will only be `true` if no domain
|
|
92
|
+
* was passed.
|
|
93
|
+
*/
|
|
94
|
+
hostOnly?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The path of the cookie.
|
|
97
|
+
*/
|
|
98
|
+
path?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the cookie is marked as secure.
|
|
101
|
+
*/
|
|
102
|
+
secure?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the cookie is marked as HTTP only.
|
|
105
|
+
*/
|
|
106
|
+
httpOnly?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Whether the cookie is a session cookie or a persistent cookie with an expiration
|
|
109
|
+
* date.
|
|
110
|
+
*/
|
|
111
|
+
session?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* The expiration date of the cookie as the number of seconds since the UNIX epoch.
|
|
114
|
+
* Not provided for session cookies.
|
|
115
|
+
*/
|
|
116
|
+
expirationDate?: number;
|
|
117
|
+
/**
|
|
118
|
+
* The Same Site policy applied to this cookie. Can be `unspecified`, `no_restriction`, `lax` or `strict`.
|
|
119
|
+
* @default unspecified
|
|
120
|
+
*/
|
|
121
|
+
sameSite: CookieSameSiteType = 'unspecified';
|
|
122
|
+
|
|
123
|
+
static fromLegacy(old: LegacyARCCookie): HttpCookie {
|
|
124
|
+
const init: IHttpCookie = {
|
|
125
|
+
name: old.name,
|
|
126
|
+
value: old.value || '',
|
|
127
|
+
sameSite: 'unspecified',
|
|
128
|
+
};
|
|
129
|
+
if (old.domain) {
|
|
130
|
+
init.domain = old.domain;
|
|
131
|
+
}
|
|
132
|
+
if (typeof old.expires === 'number') {
|
|
133
|
+
init.expirationDate = old.expires;
|
|
134
|
+
}
|
|
135
|
+
if (typeof old.hostOnly === 'boolean') {
|
|
136
|
+
init.hostOnly = old.hostOnly;
|
|
137
|
+
}
|
|
138
|
+
if (typeof old.httpOnly === 'boolean') {
|
|
139
|
+
init.httpOnly = old.httpOnly;
|
|
140
|
+
}
|
|
141
|
+
if (typeof old.path === 'string') {
|
|
142
|
+
init.path = old.path;
|
|
143
|
+
}
|
|
144
|
+
if (typeof old.secure === 'boolean') {
|
|
145
|
+
init.secure = old.secure;
|
|
146
|
+
}
|
|
147
|
+
if (typeof old.session === 'boolean') {
|
|
148
|
+
init.session = old.session;
|
|
149
|
+
}
|
|
150
|
+
return new HttpCookie(init);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static fromValue(name: string, value: string = ''): HttpCookie {
|
|
154
|
+
const init: IHttpCookie = {
|
|
155
|
+
name,
|
|
156
|
+
value,
|
|
157
|
+
sameSite: 'unspecified',
|
|
158
|
+
};
|
|
159
|
+
return new HttpCookie(init);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static fromCookieParser(cookie: ParserCookie): HttpCookie {
|
|
163
|
+
const { name, value, sameSite='unspecified' } = cookie;
|
|
164
|
+
const init: IHttpCookie = {
|
|
165
|
+
name,
|
|
166
|
+
value,
|
|
167
|
+
sameSite,
|
|
168
|
+
};
|
|
169
|
+
if (typeof cookie.domain === 'string') {
|
|
170
|
+
init.domain = cookie.domain;
|
|
171
|
+
}
|
|
172
|
+
if (typeof cookie.path === 'string') {
|
|
173
|
+
init.path = cookie.path;
|
|
174
|
+
}
|
|
175
|
+
if (typeof cookie.expires === 'number') {
|
|
176
|
+
init.expirationDate = cookie.expires;
|
|
177
|
+
}
|
|
178
|
+
if (typeof cookie.hostOnly === 'boolean') {
|
|
179
|
+
init.hostOnly = cookie.hostOnly;
|
|
180
|
+
}
|
|
181
|
+
if (typeof cookie.httpOnly === 'boolean') {
|
|
182
|
+
init.httpOnly = cookie.httpOnly;
|
|
183
|
+
}
|
|
184
|
+
if (typeof cookie.secure === 'boolean') {
|
|
185
|
+
init.secure = cookie.secure;
|
|
186
|
+
}
|
|
187
|
+
if (typeof cookie.persistent === 'boolean') {
|
|
188
|
+
init.session = !cookie.persistent;
|
|
189
|
+
}
|
|
190
|
+
return new HttpCookie(init);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
constructor(input?: string|IHttpCookie) {
|
|
194
|
+
let init: IHttpCookie;
|
|
195
|
+
if (typeof input === 'string') {
|
|
196
|
+
init = JSON.parse(input);
|
|
197
|
+
} else if (typeof input === 'object') {
|
|
198
|
+
init = input;
|
|
199
|
+
} else {
|
|
200
|
+
init = {
|
|
201
|
+
name: '',
|
|
202
|
+
value: '',
|
|
203
|
+
sameSite: 'unspecified',
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
this.new(init);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
new(init: IHttpCookie): void {
|
|
210
|
+
const {
|
|
211
|
+
name = '',
|
|
212
|
+
value = '',
|
|
213
|
+
sameSite = 'unspecified',
|
|
214
|
+
domain, expirationDate, hostOnly, httpOnly, path, secure, session
|
|
215
|
+
} = init;
|
|
216
|
+
this.name = name;
|
|
217
|
+
this.value = value;
|
|
218
|
+
this.sameSite = sameSite;
|
|
219
|
+
if (domain) {
|
|
220
|
+
this.domain = domain;
|
|
221
|
+
} else {
|
|
222
|
+
this.domain = undefined;
|
|
223
|
+
}
|
|
224
|
+
if (typeof expirationDate === 'number') {
|
|
225
|
+
this.expirationDate = expirationDate;
|
|
226
|
+
} else {
|
|
227
|
+
this.expirationDate = undefined;
|
|
228
|
+
}
|
|
229
|
+
if (typeof hostOnly === 'boolean') {
|
|
230
|
+
this.hostOnly = hostOnly;
|
|
231
|
+
} else {
|
|
232
|
+
this.hostOnly = undefined;
|
|
233
|
+
}
|
|
234
|
+
if (typeof httpOnly === 'boolean') {
|
|
235
|
+
this.httpOnly = httpOnly;
|
|
236
|
+
} else {
|
|
237
|
+
this.httpOnly = undefined;
|
|
238
|
+
}
|
|
239
|
+
if (typeof secure === 'boolean') {
|
|
240
|
+
this.secure = secure;
|
|
241
|
+
} else {
|
|
242
|
+
this.secure = undefined;
|
|
243
|
+
}
|
|
244
|
+
if (typeof session === 'boolean') {
|
|
245
|
+
this.session = session;
|
|
246
|
+
} else {
|
|
247
|
+
this.session = undefined;
|
|
248
|
+
}
|
|
249
|
+
if (typeof path === 'string') {
|
|
250
|
+
this.path = path;
|
|
251
|
+
} else {
|
|
252
|
+
this.path = undefined;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
toJSON(): IHttpCookie {
|
|
257
|
+
const result: IHttpCookie = {
|
|
258
|
+
name: this.name,
|
|
259
|
+
value: this.value,
|
|
260
|
+
sameSite: this.sameSite,
|
|
261
|
+
};
|
|
262
|
+
if (this.domain) {
|
|
263
|
+
result.domain = this.domain;
|
|
264
|
+
}
|
|
265
|
+
if (typeof this.expirationDate === 'number') {
|
|
266
|
+
result.expirationDate = this.expirationDate;
|
|
267
|
+
}
|
|
268
|
+
if (typeof this.hostOnly === 'boolean') {
|
|
269
|
+
result.hostOnly = this.hostOnly;
|
|
270
|
+
}
|
|
271
|
+
if (typeof this.httpOnly === 'boolean') {
|
|
272
|
+
result.httpOnly = this.httpOnly;
|
|
273
|
+
}
|
|
274
|
+
if (typeof this.secure === 'boolean') {
|
|
275
|
+
result.secure = this.secure;
|
|
276
|
+
}
|
|
277
|
+
if (typeof this.session === 'boolean') {
|
|
278
|
+
result.session = this.session;
|
|
279
|
+
}
|
|
280
|
+
if (this.path) {
|
|
281
|
+
result.path = this.path;
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
}
|