@api-client/core 0.3.3 → 0.3.6

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 (259) hide show
  1. package/build/browser.d.ts +3 -0
  2. package/build/browser.js +9 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +11 -2
  5. package/build/index.js +20 -2
  6. package/build/index.js.map +1 -1
  7. package/build/src/lib/fs/Fs.d.ts +52 -0
  8. package/build/src/lib/fs/Fs.js +245 -0
  9. package/build/src/lib/fs/Fs.js.map +1 -0
  10. package/build/src/lib/timers/Timers.d.ts +5 -0
  11. package/build/src/lib/timers/Timers.js +10 -0
  12. package/build/src/lib/timers/Timers.js.map +1 -0
  13. package/build/src/mocking/ProjectMock.d.ts +13 -0
  14. package/build/src/mocking/ProjectMock.js +16 -0
  15. package/build/src/mocking/ProjectMock.js.map +1 -0
  16. package/build/src/mocking/lib/Request.d.ts +32 -0
  17. package/build/src/mocking/lib/Request.js +63 -0
  18. package/build/src/mocking/lib/Request.js.map +1 -0
  19. package/build/src/mocking/lib/Response.d.ts +33 -0
  20. package/build/src/mocking/lib/Response.js +79 -0
  21. package/build/src/mocking/lib/Response.js.map +1 -0
  22. package/build/src/models/ErrorResponse.d.ts +5 -4
  23. package/build/src/models/ErrorResponse.js +18 -5
  24. package/build/src/models/ErrorResponse.js.map +1 -1
  25. package/build/src/models/SerializableError.d.ts +30 -0
  26. package/build/src/models/SerializableError.js +63 -0
  27. package/build/src/models/SerializableError.js.map +1 -0
  28. package/build/src/runtime/http-engine/ArcEngine.js +8 -4
  29. package/build/src/runtime/http-engine/ArcEngine.js.map +1 -1
  30. package/build/src/runtime/http-engine/HttpEngine.d.ts +3 -3
  31. package/build/src/runtime/http-engine/HttpEngine.js +3 -3
  32. package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
  33. package/build/src/runtime/http-engine/NodeEngine.js +9 -4
  34. package/build/src/runtime/http-engine/NodeEngine.js.map +1 -1
  35. package/build/src/runtime/http-engine/NodeEngineDirect.js +8 -2
  36. package/build/src/runtime/http-engine/NodeEngineDirect.js.map +1 -1
  37. package/build/src/runtime/node/BaseRunner.d.ts +21 -0
  38. package/build/src/runtime/node/BaseRunner.js +27 -0
  39. package/build/src/runtime/node/BaseRunner.js.map +1 -0
  40. package/build/src/runtime/node/ProjectParallelRunner.d.ts +81 -0
  41. package/build/src/runtime/node/ProjectParallelRunner.js +173 -0
  42. package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -0
  43. package/build/src/runtime/node/ProjectRequestRunner.d.ts +125 -0
  44. package/build/src/runtime/node/ProjectRequestRunner.js +185 -0
  45. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -0
  46. package/build/src/runtime/node/ProjectRunner.d.ts +166 -64
  47. package/build/src/runtime/node/ProjectRunner.js +191 -139
  48. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  49. package/build/src/runtime/node/ProjectRunnerWorker.d.ts +1 -0
  50. package/build/src/runtime/node/ProjectRunnerWorker.js +58 -0
  51. package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -0
  52. package/build/src/runtime/node/ProjectSerialRunner.d.ts +11 -0
  53. package/build/src/runtime/node/ProjectSerialRunner.js +34 -0
  54. package/build/src/runtime/node/ProjectSerialRunner.js.map +1 -0
  55. package/build/src/runtime/reporters/ProjectRunCliReporter.d.ts +7 -0
  56. package/build/src/runtime/reporters/ProjectRunCliReporter.js +73 -0
  57. package/build/src/runtime/reporters/ProjectRunCliReporter.js.map +1 -0
  58. package/build/src/runtime/reporters/Reporter.d.ts +62 -0
  59. package/build/src/runtime/reporters/Reporter.js +98 -0
  60. package/build/src/runtime/reporters/Reporter.js.map +1 -0
  61. package/build/src/testing/TestCliHelper.d.ts +23 -0
  62. package/build/src/testing/TestCliHelper.js +71 -0
  63. package/build/src/testing/TestCliHelper.js.map +1 -0
  64. package/build/src/testing/getPort.d.ts +52 -0
  65. package/build/src/testing/getPort.js +169 -0
  66. package/build/src/testing/getPort.js.map +1 -0
  67. package/package.json +2 -1
  68. package/src/data/DataReader.ts +11 -0
  69. package/src/data/DataUtils.ts +108 -0
  70. package/src/data/JmesparthReader.ts +26 -0
  71. package/src/data/Json2Xml.ts +190 -0
  72. package/src/data/JsonReader.ts +41 -0
  73. package/src/data/PayloadPointer.ts +48 -0
  74. package/src/data/RequestDataExtractor.ts +133 -0
  75. package/src/data/UrlEncodedReader.ts +20 -0
  76. package/src/data/XmlReader.ts +103 -0
  77. package/src/events/BaseEvents.ts +259 -0
  78. package/src/events/CustomEvent.ts +27 -0
  79. package/src/events/EventTypes.ts +19 -0
  80. package/src/events/Events.ts +19 -0
  81. package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
  82. package/src/events/authorization/AuthorizationEvents.ts +61 -0
  83. package/src/events/cookies/CookieEventTypes.ts +13 -0
  84. package/src/events/cookies/CookieEvents.ts +157 -0
  85. package/src/events/encryption/EncryptionEventTypes.ts +4 -0
  86. package/src/events/encryption/EncryptionEvents.ts +51 -0
  87. package/src/events/environment/EnvironmentEventTypes.ts +3 -0
  88. package/src/events/environment/EnvironmentEvents.ts +24 -0
  89. package/src/events/models/ClientCertificateEvents.ts +87 -0
  90. package/src/events/models/ModelEventTypes.ts +47 -0
  91. package/src/events/models/ModelEvents.ts +7 -0
  92. package/src/events/models/ProjectEvents.ts +331 -0
  93. package/src/events/process/ProcessEventTypes.ts +5 -0
  94. package/src/events/process/ProcessEvents.ts +76 -0
  95. package/src/events/readme.md +22 -0
  96. package/src/events/reporting/ReportingEventTypes.ts +3 -0
  97. package/src/events/reporting/ReportingEvents.ts +28 -0
  98. package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
  99. package/src/events/telemetry/TelemetryEvents.ts +156 -0
  100. package/src/lib/cookies/Cookie.ts +312 -0
  101. package/src/lib/cookies/Cookies.ts +326 -0
  102. package/src/lib/cookies/Utils.ts +168 -0
  103. package/src/lib/fs/Fs.ts +258 -0
  104. package/src/lib/headers/Headers.ts +219 -0
  105. package/src/lib/logging/DefaultLogger.ts +19 -0
  106. package/src/lib/logging/DummyLogger.ts +21 -0
  107. package/src/lib/logging/Logger.ts +16 -0
  108. package/src/lib/timers/Timers.ts +9 -0
  109. package/src/lib/transformers/PayloadSerializer.ts +332 -0
  110. package/src/lib/transformers/Utils.ts +18 -0
  111. package/src/lib/uuid.ts +40 -0
  112. package/src/mocking/LegacyInterfaces.ts +52 -0
  113. package/src/mocking/LegacyMock.ts +37 -0
  114. package/src/mocking/ProjectMock.ts +20 -0
  115. package/src/mocking/legacy/Authorization.ts +39 -0
  116. package/src/mocking/legacy/Certificates.ts +145 -0
  117. package/src/mocking/legacy/Cookies.ts +51 -0
  118. package/src/mocking/legacy/HostRules.ts +43 -0
  119. package/src/mocking/legacy/Http.ts +236 -0
  120. package/src/mocking/legacy/HttpResponse.ts +106 -0
  121. package/src/mocking/legacy/RestApi.ts +68 -0
  122. package/src/mocking/legacy/Urls.ts +44 -0
  123. package/src/mocking/legacy/Variables.ts +53 -0
  124. package/src/mocking/lib/Request.ts +85 -0
  125. package/src/mocking/lib/Response.ts +101 -0
  126. package/src/models/ArcResponse.ts +166 -0
  127. package/src/models/Authorization.ts +481 -0
  128. package/src/models/AuthorizationData.ts +60 -0
  129. package/src/models/Backend.ts +107 -0
  130. package/src/models/ClientCertificate.ts +68 -0
  131. package/src/models/Environment.ts +279 -0
  132. package/src/models/ErrorResponse.ts +113 -0
  133. package/src/models/HistoryIndex.ts +76 -0
  134. package/src/models/HistoryRequest.ts +28 -0
  135. package/src/models/HostRule.ts +163 -0
  136. package/src/models/HttpCookie.ts +285 -0
  137. package/src/models/HttpProject.ts +1294 -0
  138. package/src/models/HttpProjectListItem.ts +23 -0
  139. package/src/models/HttpRequest.ts +124 -0
  140. package/src/models/HttpResponse.ts +143 -0
  141. package/src/models/License.ts +113 -0
  142. package/src/models/ProjectDefinitionProperty.ts +40 -0
  143. package/src/models/ProjectFolder.ts +439 -0
  144. package/src/models/ProjectItem.ts +135 -0
  145. package/src/models/ProjectParent.ts +113 -0
  146. package/src/models/ProjectRequest.ts +277 -0
  147. package/src/models/ProjectSchema.ts +202 -0
  148. package/src/models/Property.ts +423 -0
  149. package/src/models/Provider.ts +98 -0
  150. package/src/models/README.md +20 -0
  151. package/src/models/Request.ts +452 -0
  152. package/src/models/RequestActions.ts +163 -0
  153. package/src/models/RequestAuthorization.ts +115 -0
  154. package/src/models/RequestConfig.ts +317 -0
  155. package/src/models/RequestLog.ts +159 -0
  156. package/src/models/RequestTime.ts +108 -0
  157. package/src/models/RequestUiMeta.ts +258 -0
  158. package/src/models/RequestsSize.ts +65 -0
  159. package/src/models/ResponseAuthorization.ts +104 -0
  160. package/src/models/ResponseRedirect.ts +158 -0
  161. package/src/models/RevisionInfo.ts +37 -0
  162. package/src/models/SentRequest.ts +125 -0
  163. package/src/models/SerializableError.ts +80 -0
  164. package/src/models/SerializablePayload.ts +68 -0
  165. package/src/models/Server.ts +153 -0
  166. package/src/models/Thing.ts +110 -0
  167. package/src/models/Url.ts +90 -0
  168. package/src/models/User.ts +120 -0
  169. package/src/models/WebApi.ts +234 -0
  170. package/src/models/WebApiIndex.ts +122 -0
  171. package/src/models/Workspace.ts +182 -0
  172. package/src/models/actions/Action.ts +213 -0
  173. package/src/models/actions/ActionView.ts +40 -0
  174. package/src/models/actions/Condition.ts +207 -0
  175. package/src/models/actions/ConditionView.ts +42 -0
  176. package/src/models/actions/Enums.ts +29 -0
  177. package/src/models/actions/RunnableAction.ts +144 -0
  178. package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
  179. package/src/models/actions/runnable/Runnable.ts +9 -0
  180. package/src/models/actions/runnable/SetCookieAction.ts +216 -0
  181. package/src/models/actions/runnable/SetVariableAction.ts +81 -0
  182. package/src/models/legacy/DataExport.ts +172 -0
  183. package/src/models/legacy/Normalizer.ts +110 -0
  184. package/src/models/legacy/actions/Actions.ts +269 -0
  185. package/src/models/legacy/authorization/Authorization.ts +572 -0
  186. package/src/models/legacy/models/ApiTypes.ts +202 -0
  187. package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
  188. package/src/models/legacy/models/AuthData.ts +17 -0
  189. package/src/models/legacy/models/ClientCertificate.ts +95 -0
  190. package/src/models/legacy/models/Cookies.ts +52 -0
  191. package/src/models/legacy/models/HostRule.ts +35 -0
  192. package/src/models/legacy/models/RestApi.ts +49 -0
  193. package/src/models/legacy/models/UrlHistory.ts +37 -0
  194. package/src/models/legacy/models/Variable.ts +43 -0
  195. package/src/models/legacy/models/base.d.ts +95 -0
  196. package/src/models/legacy/request/ArcRequest.ts +405 -0
  197. package/src/models/legacy/request/ArcResponse.ts +177 -0
  198. package/src/models/legacy/request/HistoryData.ts +47 -0
  199. package/src/models/legacy/request/Legacy.ts +45 -0
  200. package/src/models/legacy/request/RequestBody.ts +87 -0
  201. package/src/models/transformers/ArcDexieTransformer.ts +323 -0
  202. package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
  203. package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
  204. package/src/models/transformers/ArcPouchTransformer.ts +184 -0
  205. package/src/models/transformers/BaseTransformer.ts +116 -0
  206. package/src/models/transformers/ImportUtils.ts +141 -0
  207. package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
  208. package/src/models/transformers/LegacyExportProcessor.ts +252 -0
  209. package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
  210. package/src/models/transformers/PostmanDataTransformer.ts +50 -0
  211. package/src/models/transformers/PostmanTransformer.ts +106 -0
  212. package/src/models/transformers/PostmanV21Transformer.ts +311 -0
  213. package/src/models/transformers/PostmanV2Transformer.ts +308 -0
  214. package/src/models/transformers/har.ts +865 -0
  215. package/src/runtime/actions/ActionRunner.ts +83 -0
  216. package/src/runtime/actions/ConditionRunner.ts +194 -0
  217. package/src/runtime/actions/RunnableCondition.ts +57 -0
  218. package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
  219. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
  220. package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
  221. package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
  222. package/src/runtime/http-engine/ArcEngine.ts +1068 -0
  223. package/src/runtime/http-engine/FormData.ts +85 -0
  224. package/src/runtime/http-engine/HttpEngine.ts +874 -0
  225. package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
  226. package/src/runtime/http-engine/NodeEngine.ts +792 -0
  227. package/src/runtime/http-engine/NodeEngineDirect.ts +482 -0
  228. package/src/runtime/http-engine/PayloadSupport.ts +84 -0
  229. package/src/runtime/http-engine/RequestUtils.ts +164 -0
  230. package/src/runtime/http-engine/ntlm/Des.ts +345 -0
  231. package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
  232. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
  233. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
  234. package/src/runtime/modules/BasicAuthCache.ts +133 -0
  235. package/src/runtime/modules/ExecutionResponse.ts +4 -0
  236. package/src/runtime/modules/ModulesRegistry.ts +136 -0
  237. package/src/runtime/modules/RequestAuthorization.ts +110 -0
  238. package/src/runtime/modules/RequestCookies.ts +145 -0
  239. package/src/runtime/node/BaseRunner.ts +29 -0
  240. package/src/runtime/node/ProjectParallelRunner.ts +234 -0
  241. package/src/runtime/node/ProjectRequestRunner.ts +281 -0
  242. package/src/runtime/node/ProjectRunner.ts +374 -0
  243. package/src/runtime/node/ProjectRunnerWorker.ts +62 -0
  244. package/src/runtime/node/ProjectSerialRunner.ts +36 -0
  245. package/src/runtime/node/RequestFactory.ts +422 -0
  246. package/src/runtime/node/VariablesStore.ts +25 -0
  247. package/src/runtime/reporters/ProjectRunCliReporter.ts +79 -0
  248. package/src/runtime/reporters/Reporter.ts +142 -0
  249. package/src/runtime/store/StoreSdk.ts +838 -0
  250. package/src/runtime/variables/Cache.ts +53 -0
  251. package/src/runtime/variables/EvalFunctions.ts +132 -0
  252. package/src/runtime/variables/ProjectVariables.ts +6 -0
  253. package/src/runtime/variables/VariablesProcessor.ts +543 -0
  254. package/src/runtime/variables/VariablesTokenizer.ts +55 -0
  255. package/src/testing/TestCliHelper.ts +76 -0
  256. package/src/testing/getPort.ts +212 -0
  257. package/build/src/runtime/http-engine/Errors.d.ts +0 -10
  258. package/build/src/runtime/http-engine/Errors.js +0 -14
  259. package/build/src/runtime/http-engine/Errors.js.map +0 -1
@@ -0,0 +1,115 @@
1
+ import { IAuthorizationSettingsUnion, AuthorizationType } from './Authorization.js';
2
+ import { RequestAuthorization as LegacyAuthorization } from './legacy/request/ArcRequest.js';
3
+
4
+ export const Kind = 'ARC#RequestAuthorization';
5
+
6
+ /**
7
+ * Authorization configuration for the request.
8
+ */
9
+ export interface IRequestAuthorization {
10
+ kind: string;
11
+ /**
12
+ * Authorization configuration
13
+ */
14
+ config: IAuthorizationSettingsUnion;
15
+ /**
16
+ * The name of the authorization
17
+ */
18
+ type: AuthorizationType;
19
+ /**
20
+ * Whether the authorization is enabled.
21
+ */
22
+ enabled: boolean;
23
+ /**
24
+ * Whether the authorization is reported to be valid.
25
+ * The application should take action when the authorization is invalid but possibly allow the request.
26
+ */
27
+ valid: boolean;
28
+ }
29
+
30
+ export class RequestAuthorization {
31
+ kind = Kind;
32
+ /**
33
+ * Authorization configuration
34
+ */
35
+ config?: IAuthorizationSettingsUnion;
36
+ /**
37
+ * The name of the authorization
38
+ */
39
+ type?: AuthorizationType;
40
+ /**
41
+ * Whether the authorization is enabled.
42
+ */
43
+ enabled?: boolean;
44
+ /**
45
+ * Whether the authorization is reported to be valid.
46
+ * The application should take action when the authorization is invalid but possibly allow the request.
47
+ */
48
+ valid?: boolean;
49
+
50
+ static fromTypedConfig(type: AuthorizationType, config: IAuthorizationSettingsUnion, valid=true): RequestAuthorization {
51
+ return new RequestAuthorization({
52
+ kind: Kind,
53
+ config,
54
+ enabled: true,
55
+ type,
56
+ valid,
57
+ });
58
+ }
59
+
60
+ static fromLegacy(info: LegacyAuthorization): RequestAuthorization {
61
+ return new RequestAuthorization({
62
+ kind: Kind,
63
+ config: info.config,
64
+ enabled: true,
65
+ type: info.type as AuthorizationType,
66
+ valid: info.valid,
67
+ });
68
+ }
69
+
70
+ /**
71
+ * @param input The provider definition used to restore the state.
72
+ */
73
+ constructor(input?: string|IRequestAuthorization) {
74
+ let init: IRequestAuthorization;
75
+ if (typeof input === 'string') {
76
+ init = JSON.parse(input);
77
+ } else if (typeof input === 'object') {
78
+ init = input;
79
+ } else {
80
+ init = {
81
+ kind: Kind,
82
+ config: {},
83
+ enabled: false,
84
+ type: '' as AuthorizationType,
85
+ valid: true,
86
+ };
87
+ }
88
+ this.new(init);
89
+ }
90
+
91
+ /**
92
+ * Creates a new provider clearing anything that is so far defined.
93
+ *
94
+ * Note, this throws an error when the provider is not an ARC provider object.
95
+ */
96
+ new(init: IRequestAuthorization): void {
97
+ const { config, type, enabled, valid } = init;
98
+ this.kind = Kind;
99
+ this.config = config;
100
+ this.type = type;
101
+ this.enabled = enabled;
102
+ this.valid = valid;
103
+ }
104
+
105
+ toJSON(): IRequestAuthorization {
106
+ const result:IRequestAuthorization = {
107
+ kind: Kind,
108
+ config: this.config || {},
109
+ enabled: this.enabled || false,
110
+ type: this.type || '' as AuthorizationType,
111
+ valid: this.valid || true,
112
+ };
113
+ return result;
114
+ }
115
+ }
@@ -0,0 +1,317 @@
1
+ import { IHostRule, HostRule } from './HostRule.js';
2
+ import { IProperty, Property } from './Property.js';
3
+ import { RequestConfig as LegacyConfig } from './legacy/request/ArcRequest.js';
4
+
5
+ export const Kind = 'ARC#RequestConfig';
6
+
7
+ export interface IRequestBaseConfig {
8
+ /**
9
+ * Request timeout in milliseconds
10
+ * Default no timeout.
11
+ */
12
+ timeout?: number;
13
+ /**
14
+ * When false the request object won't follow redirects.
15
+ * @default true
16
+ */
17
+ followRedirects?: boolean;
18
+ /**
19
+ * Hosts table configuration.
20
+ */
21
+ hosts?: IHostRule[];
22
+ /**
23
+ * A limit of characters to include into the `sentHttpMessage` property
24
+ * of the request object. 0 to disable limit. Default to 2048.
25
+ * @default 2048
26
+ */
27
+ sentMessageLimit?: number;
28
+ /**
29
+ * When set the request adds `accept` and `user-agent` headers if missing.
30
+ */
31
+ defaultHeaders?: boolean;
32
+ /**
33
+ * Default `user-agent` header to be used with request when `defaultHeaders`
34
+ * is set.
35
+ *
36
+ * @default api-client
37
+ */
38
+ defaultUserAgent?: string;
39
+ /**
40
+ * Default `accept` header to be used with request when `defaultHeaders`
41
+ * is set.
42
+ * @default *\/*
43
+ */
44
+ defaultAccept?: string;
45
+ /**
46
+ * The proxy URI to connect to when making the connection.
47
+ * It should contain the host and port. Default port is 80.
48
+ */
49
+ proxy?: string;
50
+ /**
51
+ * The proxy authorization username value.
52
+ */
53
+ proxyUsername?: string;
54
+ /**
55
+ * The proxy authorization password value.
56
+ */
57
+ proxyPassword?: string;
58
+ /**
59
+ * Whether the processor should validate certificates.
60
+ */
61
+ validateCertificates?: boolean;
62
+ }
63
+
64
+ /**
65
+ * ARC request `config` object.
66
+ */
67
+ export interface IRequestConfig extends IRequestBaseConfig {
68
+ kind: string;
69
+ /**
70
+ * Whether the processor should use this configuration.
71
+ */
72
+ enabled: boolean;
73
+ /**
74
+ * Does not set session (saved) cookies to this request
75
+ */
76
+ ignoreSessionCookies?: boolean;
77
+ /**
78
+ * A list of variables to use with the request.
79
+ * Note, request variables override application and workspace variables.
80
+ */
81
+ variables?: IProperty[];
82
+ }
83
+
84
+ export class RequestConfig {
85
+ kind = Kind;
86
+ /**
87
+ * Whether the processor should use this configuration.
88
+ */
89
+ enabled = false;
90
+ /**
91
+ * The request timeout.
92
+ * Default no timeout.
93
+ */
94
+ timeout?: number;
95
+ /**
96
+ * Whether or not the request should follow redirects.
97
+ */
98
+ followRedirects?: boolean;
99
+ /**
100
+ * Does not set session (saved) cookies to this request
101
+ */
102
+ ignoreSessionCookies?: boolean;
103
+ /**
104
+ * Hosts table configuration.
105
+ */
106
+ hosts?: HostRule[];
107
+ /**
108
+ * Whether the processor should validate certificates.
109
+ */
110
+ validateCertificates?: boolean;
111
+ /**
112
+ * Whether to put a "default" headers (accept and user agent)
113
+ */
114
+ defaultHeaders?: boolean;
115
+ /**
116
+ * Default `user-agent` header to be used with request when `defaultHeaders`
117
+ * is set.
118
+ *
119
+ * @default api-client
120
+ */
121
+ defaultUserAgent?: string;
122
+ /**
123
+ * Default `accept` header to be used with request when `defaultHeaders`
124
+ * is set.
125
+ * @default *\/*
126
+ */
127
+ defaultAccept?: string;
128
+ /**
129
+ * A list of variables to use with the request.
130
+ * Note, request variables override application and workspace variables.
131
+ */
132
+ variables?: Property[];
133
+ /**
134
+ * The proxy URI to connect to when making the connection.
135
+ * It should contain the host and port. Default port is 80.
136
+ */
137
+ proxy?: string;
138
+ /**
139
+ * The proxy authorization username value.
140
+ */
141
+ proxyUsername?: string;
142
+ /**
143
+ * The proxy authorization password value.
144
+ */
145
+ proxyPassword?: string;
146
+ /**
147
+ * A limit of characters to include into the `sentHttpMessage` property
148
+ * of the request object. 0 to disable limit. Default to 2048.
149
+ * @default 2048
150
+ */
151
+ sentMessageLimit?: number;
152
+
153
+ static withDefaults(): RequestConfig {
154
+ return new RequestConfig({
155
+ kind: Kind,
156
+ enabled: true,
157
+ timeout: 90,
158
+ followRedirects: true,
159
+ ignoreSessionCookies: false,
160
+ validateCertificates: false,
161
+ });
162
+ }
163
+
164
+ static fromLegacy(config: LegacyConfig): RequestConfig {
165
+ const { enabled, defaultHeaders, followRedirects, ignoreSessionCookies, timeout, validateCertificates } = config;
166
+ const init: IRequestConfig = {
167
+ kind: Kind,
168
+ enabled,
169
+ };
170
+ if (typeof defaultHeaders === 'boolean') {
171
+ init.defaultHeaders = defaultHeaders;
172
+ }
173
+ if (typeof followRedirects === 'boolean') {
174
+ init.followRedirects = followRedirects;
175
+ }
176
+ if (typeof ignoreSessionCookies === 'boolean') {
177
+ init.ignoreSessionCookies = ignoreSessionCookies;
178
+ }
179
+ if (typeof validateCertificates === 'boolean') {
180
+ init.validateCertificates = validateCertificates;
181
+ }
182
+ if (typeof timeout === 'number') {
183
+ init.timeout = timeout;
184
+ }
185
+ return new RequestConfig(init);
186
+ }
187
+
188
+ /**
189
+ * @param input The request configuration definition used to restore the state.
190
+ */
191
+ constructor(input?: string | IRequestConfig) {
192
+ let init: IRequestConfig;
193
+ if (typeof input === 'string') {
194
+ init = JSON.parse(input);
195
+ } else if (typeof input === 'object') {
196
+ init = input;
197
+ } else {
198
+ init = {
199
+ kind: Kind,
200
+ enabled: false,
201
+ }
202
+ }
203
+ this.new(init);
204
+ }
205
+
206
+ /**
207
+ * Creates a new request configuration clearing anything that is so far defined.
208
+ *
209
+ * Note, this throws an error when the object is not an ARC request configuration.
210
+ */
211
+ new(init: IRequestConfig): void {
212
+ const {
213
+ enabled, followRedirects, ignoreSessionCookies, validateCertificates, defaultHeaders, timeout, hosts, variables,
214
+ defaultAccept, defaultUserAgent, proxy, proxyPassword, proxyUsername, sentMessageLimit,
215
+ } = init;
216
+ this.kind = Kind;
217
+ if (typeof enabled === 'boolean') {
218
+ this.enabled = enabled;
219
+ } else {
220
+ this.enabled = false;
221
+ }
222
+ if (typeof followRedirects === 'boolean') {
223
+ this.followRedirects = followRedirects;
224
+ } else {
225
+ this.followRedirects = undefined;
226
+ }
227
+ if (typeof ignoreSessionCookies === 'boolean') {
228
+ this.ignoreSessionCookies = ignoreSessionCookies;
229
+ } else {
230
+ this.ignoreSessionCookies = undefined;
231
+ }
232
+ if (typeof validateCertificates === 'boolean') {
233
+ this.validateCertificates = validateCertificates;
234
+ } else {
235
+ this.validateCertificates = undefined;
236
+ }
237
+ if (typeof defaultHeaders === 'boolean') {
238
+ this.defaultHeaders = defaultHeaders;
239
+ } else {
240
+ this.defaultHeaders = undefined;
241
+ }
242
+ if (typeof timeout === 'number') {
243
+ this.timeout = timeout;
244
+ } else {
245
+ this.timeout = undefined;
246
+ }
247
+ if (Array.isArray(hosts)) {
248
+ this.hosts = hosts.map(i => new HostRule(i))
249
+ } else {
250
+ this.hosts = [];
251
+ }
252
+ if (Array.isArray(variables)) {
253
+ this.variables = variables.map(i => new Property(i))
254
+ } else {
255
+ this.variables = [];
256
+ }
257
+ if (typeof defaultAccept === 'string') {
258
+ this.defaultAccept = defaultAccept;
259
+ } else {
260
+ this.defaultAccept = undefined;
261
+ }
262
+ if (typeof defaultUserAgent === 'string') {
263
+ this.defaultUserAgent = defaultUserAgent;
264
+ } else {
265
+ this.defaultUserAgent = undefined;
266
+ }
267
+ if (typeof proxy === 'string') {
268
+ this.proxy = proxy;
269
+ } else {
270
+ this.proxy = undefined;
271
+ }
272
+ if (typeof proxyUsername === 'string') {
273
+ this.proxyUsername = proxyUsername;
274
+ } else {
275
+ this.proxyUsername = undefined;
276
+ }
277
+ if (typeof proxyPassword === 'string') {
278
+ this.proxyPassword = proxyPassword;
279
+ } else {
280
+ this.proxyPassword = undefined;
281
+ }
282
+ if (typeof sentMessageLimit === 'number') {
283
+ this.sentMessageLimit = sentMessageLimit;
284
+ } else {
285
+ this.sentMessageLimit = undefined;
286
+ }
287
+ }
288
+
289
+ toJSON(): IRequestConfig {
290
+ const result: IRequestConfig = {
291
+ kind: Kind,
292
+ enabled: this.enabled,
293
+ };
294
+ if (typeof this.followRedirects === 'boolean') {
295
+ result.followRedirects = this.followRedirects;
296
+ }
297
+ if (typeof this.ignoreSessionCookies === 'boolean') {
298
+ result.ignoreSessionCookies = this.ignoreSessionCookies;
299
+ }
300
+ if (typeof this.validateCertificates === 'boolean') {
301
+ result.validateCertificates = this.validateCertificates;
302
+ }
303
+ if (typeof this.defaultHeaders === 'boolean') {
304
+ result.defaultHeaders = this.defaultHeaders;
305
+ }
306
+ if (typeof this.timeout === 'number') {
307
+ result.timeout = this.timeout;
308
+ }
309
+ if (Array.isArray(this.hosts)) {
310
+ result.hosts = this.hosts.map(i => i.toJSON());
311
+ }
312
+ if (Array.isArray(this.variables)) {
313
+ result.variables = this.variables.map(i => i.toJSON());
314
+ }
315
+ return result;
316
+ }
317
+ }
@@ -0,0 +1,159 @@
1
+ import { IResponseRedirect, ResponseRedirect } from './ResponseRedirect.js';
2
+ import { ISentRequest, SentRequest } from './SentRequest.js';
3
+ import { IErrorResponse, ErrorResponse } from './ErrorResponse.js';
4
+ import { IArcResponse, ArcResponse } from './ArcResponse.js';
5
+ import { IRequestsSize, RequestsSize } from './RequestsSize.js';
6
+ import { ResponseRedirect as LegacyRedirect } from './legacy/request/ArcResponse.js';
7
+
8
+ export const Kind = 'ARC#ResponseLog';
9
+
10
+ /**
11
+ * Describes a request / response pair associated with a request.
12
+ */
13
+ export interface IRequestLog {
14
+ kind: 'ARC#ResponseLog';
15
+ /**
16
+ * Describes an HTTP request sent by the transport.
17
+ */
18
+ request?: ISentRequest;
19
+ /**
20
+ * The last response made with this request, if any.
21
+ */
22
+ response?: IArcResponse | IErrorResponse;
23
+ /**
24
+ * The list of redirects, if any.
25
+ */
26
+ redirects?: IResponseRedirect[];
27
+ /**
28
+ * Request and response size. Some HTTP clients may not give this information.
29
+ */
30
+ size?: IRequestsSize;
31
+ }
32
+
33
+ /**
34
+ * A request / response pair associated with a request.
35
+ */
36
+ export class RequestLog {
37
+ kind = Kind;
38
+ /**
39
+ * Describes an HTTP request sent by the transport.
40
+ */
41
+ request?: SentRequest;
42
+ /**
43
+ * The last response made with this request, if any.
44
+ */
45
+ response?: ArcResponse | ErrorResponse;
46
+ /**
47
+ * The list of redirects, if any.
48
+ */
49
+ redirects?: ResponseRedirect[];
50
+ /**
51
+ * Request and response size. Some HTTP clients may not give this information.
52
+ */
53
+ size?: RequestsSize;
54
+
55
+ static fromRequest(request: ISentRequest): RequestLog {
56
+ return new RequestLog({
57
+ kind: Kind,
58
+ request,
59
+ });
60
+ }
61
+
62
+ static fromRequestResponse(request: ISentRequest, response: IArcResponse | IErrorResponse): RequestLog {
63
+ return new RequestLog({
64
+ kind: Kind,
65
+ request,
66
+ response,
67
+ });
68
+ }
69
+
70
+ /**
71
+ * @param input The response definition used to restore the state.
72
+ */
73
+ constructor(input?: string|IRequestLog) {
74
+ let init: IRequestLog;
75
+ if (typeof input === 'string') {
76
+ init = JSON.parse(input);
77
+ } else if (typeof input === 'object') {
78
+ init = input;
79
+ } else {
80
+ init = {
81
+ kind: Kind,
82
+ };
83
+ }
84
+ this.new(init);
85
+ }
86
+
87
+ /**
88
+ * Creates a new response clearing anything that is so far defined.
89
+ *
90
+ * Note, this throws an error when the object is not an ARC response.
91
+ */
92
+ new(init: IRequestLog): void {
93
+ const { request, response, redirects, size } = init;
94
+ this.kind = Kind;
95
+ if (request) {
96
+ this.request = new SentRequest(request);
97
+ }
98
+ if (response) {
99
+ if (ArcResponse.isErrorResponse(response)) {
100
+ this.response = new ErrorResponse(response as IErrorResponse);
101
+ } else {
102
+ this.response = new ArcResponse(response as IArcResponse);
103
+ }
104
+ } else {
105
+ this.response = undefined;
106
+ }
107
+ if (Array.isArray(redirects)) {
108
+ this.redirects = redirects.map(i => new ResponseRedirect(i));
109
+ } else {
110
+ this.redirects = undefined;
111
+ }
112
+ if (size) {
113
+ this.size = new RequestsSize(size);
114
+ } else {
115
+ this.size = undefined;
116
+ }
117
+ }
118
+
119
+ toJSON(): IRequestLog {
120
+ const result: IRequestLog = {
121
+ kind: Kind,
122
+ };
123
+ if (this.request) {
124
+ result.request = this.request.toJSON();
125
+ }
126
+ if (Array.isArray(this.redirects)) {
127
+ result.redirects = this.redirects.map(i => i.toJSON());
128
+ }
129
+ if (this.size) {
130
+ result.size = this.size.toJSON();
131
+ }
132
+ if (this.response) {
133
+ result.response = this.response.toJSON();
134
+ }
135
+ return result;
136
+ }
137
+
138
+ /**
139
+ * Adds a redirect to this log.
140
+ * It checks whether the redirects array has been initialized.
141
+ */
142
+ addRedirect(redirect: IResponseRedirect): ResponseRedirect {
143
+ if (!this.redirects) {
144
+ this.redirects = [];
145
+ }
146
+ const instance = new ResponseRedirect(redirect);
147
+ this.redirects.push(instance);
148
+ return instance;
149
+ }
150
+
151
+ async addLegacyRedirect(redirect: LegacyRedirect): Promise<ResponseRedirect> {
152
+ if (!this.redirects) {
153
+ this.redirects = [];
154
+ }
155
+ const info = await ResponseRedirect.fromLegacy(redirect);
156
+ this.redirects.push(info);
157
+ return info;
158
+ }
159
+ }
@@ -0,0 +1,108 @@
1
+ export const Kind = 'ARC#RequestTime';
2
+
3
+ /**
4
+ * Schema definition for ARC request timings. This is mostly consistent with HAR timings.
5
+ */
6
+ export interface IRequestTime {
7
+ kind?: 'ARC#RequestTime';
8
+ connect: number;
9
+ receive: number;
10
+ send: number;
11
+ wait: number;
12
+ blocked: number;
13
+ dns: number;
14
+ ssl?: number;
15
+ }
16
+
17
+
18
+ export class RequestTime {
19
+ kind = Kind;
20
+ connect = -1;
21
+ receive = -1;
22
+ send = -1;
23
+ wait = -1;
24
+ blocked = -1;
25
+ dns = -1;
26
+ ssl?: number;
27
+
28
+ /**
29
+ * @param input The timings definition used to restore the state.
30
+ */
31
+ constructor(input?: string|IRequestTime) {
32
+ let init: IRequestTime;
33
+ if (typeof input === 'string') {
34
+ init = JSON.parse(input);
35
+ } else if (typeof input === 'object') {
36
+ init = input;
37
+ } else {
38
+ init = {
39
+ connect: -1,
40
+ receive: -1,
41
+ send: -1,
42
+ wait: -1,
43
+ blocked: -1,
44
+ dns: -1,
45
+ };
46
+ }
47
+ this.new(init);
48
+ }
49
+
50
+ /**
51
+ * Creates a new thing clearing anything that is so far defined.
52
+ *
53
+ * Note, this throws an error when the server is not an ARC thing.
54
+ */
55
+ new(init: IRequestTime): void {
56
+ const { connect=-1, receive=-1, send=-1, wait=-1, blocked=-1, dns=-1, ssl=-1 } = init;
57
+ this.kind = Kind;
58
+ this.connect = connect;
59
+ this.receive = receive;
60
+ this.send = send;
61
+ this.wait = wait;
62
+ this.blocked = blocked;
63
+ this.dns = dns;
64
+ this.ssl = ssl;
65
+ }
66
+
67
+ toJSON(): IRequestTime {
68
+ const result: IRequestTime = {
69
+ kind: Kind,
70
+ connect: this.connect,
71
+ receive: this.receive,
72
+ send: this.send,
73
+ wait: this.wait,
74
+ blocked: this.blocked,
75
+ dns: this.dns,
76
+ };
77
+ if (typeof this.ssl === 'number') {
78
+ result.ssl = this.ssl;
79
+ }
80
+ return result;
81
+ }
82
+
83
+ total(): number {
84
+ let result = 0;
85
+ if (typeof this.connect === 'number' && this.connect > 0) {
86
+ result += this.connect;
87
+ }
88
+ if (typeof this.receive === 'number' && this.receive > 0) {
89
+ result += this.receive;
90
+ }
91
+ if (typeof this.send === 'number' && this.send > 0) {
92
+ result += this.send;
93
+ }
94
+ if (typeof this.wait === 'number' && this.wait > 0) {
95
+ result += this.wait;
96
+ }
97
+ if (typeof this.blocked === 'number' && this.blocked > 0) {
98
+ result += this.blocked;
99
+ }
100
+ if (typeof this.dns === 'number' && this.dns > 0) {
101
+ result += this.dns;
102
+ }
103
+ if (typeof this.ssl === 'number' && this.ssl > 0) {
104
+ result += this.ssl;
105
+ }
106
+ return result;
107
+ }
108
+ }