@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,258 @@
1
+ import { IProperty, Property } from './Property.js';
2
+ import { IMultipartBody } from '../lib/transformers/PayloadSerializer.js';
3
+ import { RequestUiMeta as LegacyRequestUiMeta } from './legacy/request/ArcRequest.js';
4
+
5
+ export const Kind = 'ARC#RequestUiMeta';
6
+
7
+ /**
8
+ * URL editor meta data.
9
+ */
10
+ export interface IUrlMeta {
11
+ /**
12
+ * The model generated for the URL parameters.
13
+ */
14
+ model?: IProperty[];
15
+ /**
16
+ * The query params delimiter. By default it is `&`.
17
+ */
18
+ delimiter?: string;
19
+ }
20
+
21
+ /**
22
+ * Headers editor meta data.
23
+ */
24
+ export interface IHeadersMeta {
25
+ /**
26
+ * The model generated for the headers editor.
27
+ */
28
+ model?: IProperty[];
29
+ /**
30
+ * Whether the source editor is opened.
31
+ */
32
+ source?: boolean;
33
+ }
34
+
35
+ export interface IAuthMeta {
36
+ /**
37
+ * The index of the selected authorization method.
38
+ */
39
+ selected?: number;
40
+ }
41
+
42
+ export interface IActionsMeta {
43
+ /**
44
+ * The index of the selected arc actions view.
45
+ */
46
+ selected?: number;
47
+ }
48
+
49
+ export interface IResponseUiMeta {
50
+ /**
51
+ * The list of activated panels in the response view.
52
+ */
53
+ activePanels?: string[];
54
+ /**
55
+ * The name of the selected response panel.
56
+ */
57
+ selectedPanel?: string;
58
+ }
59
+
60
+ /**
61
+ * The body editor may produce multiple view models
62
+ * for the UI. Each editor can store it's data in here
63
+ * to restore it after opening a request,
64
+ */
65
+ export interface IBodyMetaModel {
66
+ /**
67
+ * The id of the editor. Each editor in ARC has own id.
68
+ */
69
+ type: string;
70
+ /**
71
+ * Generated view model.
72
+ */
73
+ viewModel: (IProperty | IMultipartBody | IRawBody)[];
74
+ }
75
+
76
+ /**
77
+ * Body editor meta data.
78
+ */
79
+ export interface IBodyMeta {
80
+ /**
81
+ * The model generated for the body editor.
82
+ */
83
+ model?: IBodyMetaModel[];
84
+ /**
85
+ * The selected editor
86
+ */
87
+ selected?: string;
88
+ }
89
+
90
+ export interface IRawBody {
91
+ /**
92
+ * The last used body value.
93
+ */
94
+ value: string;
95
+ /**
96
+ * True when the generator was used to build the value
97
+ */
98
+ isGenerator?: boolean;
99
+ /**
100
+ * The schema for the generator. Work in progress.
101
+ */
102
+ generatorSchema?: unknown;
103
+ }
104
+
105
+ /**
106
+ * UI configuration for the request.
107
+ */
108
+ export interface IRequestUiMeta {
109
+ kind?: typeof Kind;
110
+ /**
111
+ * Body editor metadata.
112
+ */
113
+ body?: IBodyMeta;
114
+ /**
115
+ * URL editor metadata.
116
+ */
117
+ url?: IUrlMeta;
118
+ /**
119
+ * Headers editor metadata.
120
+ */
121
+ headers?: IHeadersMeta;
122
+ /**
123
+ * Authorization editor meta.
124
+ */
125
+ authorization?: IAuthMeta;
126
+ /**
127
+ * ARC request actions editor UI config.
128
+ */
129
+ actions?: IActionsMeta;
130
+ /**
131
+ * The currently selected editor in the request editor UI.
132
+ */
133
+ selectedEditor?: number;
134
+ /**
135
+ * Optional configuration of the response view
136
+ */
137
+ response?: IResponseUiMeta;
138
+ }
139
+
140
+ export class RequestUiMeta {
141
+ kind = Kind;
142
+ /**
143
+ * Body editor metadata.
144
+ */
145
+ body?: IBodyMeta;
146
+ /**
147
+ * URL editor metadata.
148
+ */
149
+ url?: IUrlMeta;
150
+ /**
151
+ * Headers editor metadata.
152
+ */
153
+ headers?: IHeadersMeta;
154
+ /**
155
+ * Authorization editor meta.
156
+ */
157
+ authorization?: IAuthMeta;
158
+ /**
159
+ * ARC request actions editor UI config.
160
+ */
161
+ actions?: IActionsMeta;
162
+ /**
163
+ * The currently selected editor in the request editor UI.
164
+ */
165
+ selectedEditor?: number;
166
+ /**
167
+ * Optional configuration of the response view
168
+ */
169
+ response?: IResponseUiMeta;
170
+
171
+ static fromLegacy(old: LegacyRequestUiMeta): RequestUiMeta {
172
+ const { actions, authorization, body, headers, response, selectedEditor, url } = old;
173
+ const init: IRequestUiMeta = {
174
+ actions,
175
+ authorization,
176
+ body,
177
+ response,
178
+ selectedEditor,
179
+ };
180
+ if (url) {
181
+ const initUrl: IUrlMeta = {};
182
+ if (url.delimiter) {
183
+ initUrl.delimiter = url.delimiter;
184
+ }
185
+ if (Array.isArray(url.model) && url.model.length) {
186
+ initUrl.model = url.model.map(i => Property.fromApiType(i).toJSON());
187
+ }
188
+ init.url = initUrl;
189
+ }
190
+ if (headers) {
191
+ const headersUrl: IHeadersMeta = {};
192
+ if (typeof headers.source === 'boolean') {
193
+ headersUrl.source = headers.source;
194
+ }
195
+ if (Array.isArray(headers.model) && headers.model.length) {
196
+ headersUrl.model = headers.model.map(i => Property.fromApiType(i).toJSON());
197
+ }
198
+ init.url = headersUrl;
199
+ }
200
+ return new RequestUiMeta(init);
201
+ }
202
+
203
+ /**
204
+ * @param input The project item definition used to restore the state.
205
+ */
206
+ constructor(input?: string | IRequestUiMeta) {
207
+ let init: IRequestUiMeta;
208
+ if (typeof input === 'string') {
209
+ init = JSON.parse(input);
210
+ } else if (typeof input === 'object') {
211
+ init = input;
212
+ } else {
213
+ init = {};
214
+ }
215
+ this.new(init);
216
+ }
217
+
218
+ /**
219
+ * Creates a new object clearing anything that is so far defined.
220
+ */
221
+ new(init: IRequestUiMeta): void {
222
+ this.body = init.body;
223
+ this.url = init.url;
224
+ this.headers = init.headers;
225
+ this.authorization = init.authorization;
226
+ this.actions = init.actions;
227
+ this.selectedEditor = init.selectedEditor;
228
+ this.response = init.response;
229
+ }
230
+
231
+ toJSON(): IRequestUiMeta {
232
+ const result: IRequestUiMeta = {
233
+ kind: Kind,
234
+ };
235
+ if (this.body) {
236
+ result.body = this.body;
237
+ }
238
+ if (this.url) {
239
+ result.url = this.url;
240
+ }
241
+ if (this.headers) {
242
+ result.headers = this.headers;
243
+ }
244
+ if (this.authorization) {
245
+ result.authorization = this.authorization;
246
+ }
247
+ if (this.actions) {
248
+ result.actions = this.actions;
249
+ }
250
+ if (this.response) {
251
+ result.response = this.response;
252
+ }
253
+ if (typeof this.selectedEditor === 'number') {
254
+ result.selectedEditor = this.selectedEditor;
255
+ }
256
+ return result;
257
+ }
258
+ }
@@ -0,0 +1,65 @@
1
+ export const Kind = 'ARC#ResponseSize';
2
+
3
+ export interface IRequestsSize {
4
+ kind?: typeof Kind;
5
+ /**
6
+ * The size of the request in bytes
7
+ */
8
+ request: number;
9
+ /**
10
+ * The size of the response in bytes
11
+ */
12
+ response: number;
13
+ }
14
+
15
+ export class RequestsSize {
16
+ kind = Kind;
17
+ /**
18
+ * The size of the request in bytes
19
+ */
20
+ request = 0;
21
+ /**
22
+ * The size of the response in bytes
23
+ */
24
+ response = 0;
25
+
26
+ /**
27
+ * @param input The response size definition used to restore the state.
28
+ */
29
+ constructor(input?: string|IRequestsSize) {
30
+ let init: IRequestsSize;
31
+ if (typeof input === 'string') {
32
+ init = JSON.parse(input);
33
+ } else if (typeof input === 'object') {
34
+ init = input;
35
+ } else {
36
+ init = {
37
+ kind: Kind,
38
+ request: 0,
39
+ response: 0,
40
+ };
41
+ }
42
+ this.new(init);
43
+ }
44
+
45
+ /**
46
+ * Creates a new response size clearing anything that is so far defined.
47
+ *
48
+ * Note, this throws an error when the object is not an ARC response size.
49
+ */
50
+ new(init: IRequestsSize): void {
51
+ const { request, response } = init;
52
+ this.kind = Kind;
53
+ this.request = request;
54
+ this.response = response;
55
+ }
56
+
57
+ toJSON(): IRequestsSize {
58
+ const result: IRequestsSize = {
59
+ kind: Kind,
60
+ request: this.request,
61
+ response: this.response,
62
+ };
63
+ return result;
64
+ }
65
+ }
@@ -0,0 +1,104 @@
1
+ export const Kind = 'ARC#ResponseAuthorization';
2
+
3
+ export interface IResponseAuthorization {
4
+ kind: 'ARC#ResponseAuthorization';
5
+ /**
6
+ * The requested by the authorization server authentication method
7
+ */
8
+ method: string;
9
+ /**
10
+ * The current state if the authorization process. This is used by NTLM authorization helper.
11
+ */
12
+ state?: number;
13
+ /**
14
+ * The headers association with the response.
15
+ */
16
+ headers?: string;
17
+ /**
18
+ * When returned by the server, the value of the challenge.
19
+ */
20
+ challengeHeader?: string;
21
+ }
22
+
23
+ export class ResponseAuthorization {
24
+ kind = Kind;
25
+ /**
26
+ * The requested by the authorization server authentication method
27
+ */
28
+ method = 'unknown';
29
+ /**
30
+ * The current state if the authorization process. This is used by NTLM authorization helper.
31
+ */
32
+ state?: number;
33
+ /**
34
+ * The headers association with the response.
35
+ */
36
+ headers?: string;
37
+ /**
38
+ * When returned by the server, the value of the challenge.
39
+ */
40
+ challengeHeader?: string;
41
+
42
+ /**
43
+ * @param input The response authorization definition used to restore the state.
44
+ */
45
+ constructor(input?: string|IResponseAuthorization) {
46
+ let init: IResponseAuthorization;
47
+ if (typeof input === 'string') {
48
+ init = JSON.parse(input);
49
+ } else if (typeof input === 'object') {
50
+ init = input;
51
+ } else {
52
+ init = {
53
+ kind: Kind,
54
+ method: 'unknown',
55
+ };
56
+ }
57
+ this.new(init);
58
+ }
59
+
60
+ /**
61
+ * Creates a new response authorization clearing anything that is so far defined.
62
+ *
63
+ * Note, this throws an error when the object is not an ARC response authorization.
64
+ */
65
+ new(init: IResponseAuthorization): void {
66
+ if (!ResponseAuthorization.isResponseAuthorization(init)) {
67
+ throw new Error(`Not an ARC response authorization.`);
68
+ }
69
+ const { method, state, headers, challengeHeader } = init;
70
+ this.kind = Kind;
71
+ this.method = method;
72
+ this.state = state;
73
+ this.headers = headers;
74
+ this.challengeHeader = challengeHeader;
75
+ }
76
+
77
+ /**
78
+ * Checks whether the input is a definition of a response authorization.
79
+ */
80
+ static isResponseAuthorization(input: unknown): boolean {
81
+ const typed = input as IResponseAuthorization;
82
+ if (!input || !typed.method) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+
88
+ toJSON(): IResponseAuthorization {
89
+ const result: IResponseAuthorization = {
90
+ kind: Kind,
91
+ method: this.method,
92
+ };
93
+ if (typeof this.state === 'number') {
94
+ result.state = this.state;
95
+ }
96
+ if (this.headers) {
97
+ result.headers = this.headers;
98
+ }
99
+ if (this.challengeHeader) {
100
+ result.challengeHeader = this.challengeHeader;
101
+ }
102
+ return result;
103
+ }
104
+ }
@@ -0,0 +1,158 @@
1
+ import { IHttpResponse, HttpResponse, Kind as ResponseKind } from './HttpResponse.js';
2
+ import { IRequestTime, RequestTime } from './RequestTime.js';
3
+ import { ResponseRedirect as LegacyRedirect } from './legacy/request/ArcResponse.js';
4
+
5
+ export const Kind = 'ARC#HttpResponseRedirect';
6
+
7
+ /**
8
+ * An information about a redirect
9
+ */
10
+ export interface IResponseRedirect {
11
+ kind: string;
12
+ /**
13
+ * Redirection response
14
+ */
15
+ response: IHttpResponse;
16
+ /**
17
+ * Redirection timings, if available.
18
+ */
19
+ timings?: IRequestTime;
20
+ /**
21
+ * The timestamp when the request was started (before the connection is made)
22
+ */
23
+ startTime: number;
24
+ /**
25
+ * The timestamp of when the response ended.
26
+ */
27
+ endTime: number;
28
+ /**
29
+ * The URL the request was redirected to
30
+ */
31
+ url: string;
32
+ }
33
+
34
+
35
+ export class ResponseRedirect {
36
+ kind = Kind;
37
+ /**
38
+ * Redirection response
39
+ */
40
+ response?: HttpResponse;
41
+ /**
42
+ * Redirection timings, if available.
43
+ */
44
+ timings?: RequestTime;
45
+ /**
46
+ * The timestamp when the request was started (before the connection is made)
47
+ */
48
+ startTime = 0;
49
+ /**
50
+ * The timestamp of when the response ended.
51
+ */
52
+ endTime = 0;
53
+ /**
54
+ * The URL the request was redirected to
55
+ */
56
+ url = '';
57
+
58
+ /**
59
+ * Creates a redirect object from basic values.
60
+ * @param url The redirect URL
61
+ * @param response The response object created by the transport
62
+ * @param startTime The time when the request started
63
+ * @param endTime The time when the request ended
64
+ */
65
+ static fromValues(url: string, response: IHttpResponse, startTime = 0, endTime = 0): ResponseRedirect {
66
+ return new ResponseRedirect({
67
+ kind: Kind,
68
+ url,
69
+ startTime,
70
+ endTime,
71
+ response,
72
+ });
73
+ }
74
+
75
+ static async fromLegacy(redirect: LegacyRedirect): Promise<ResponseRedirect> {
76
+ const init: IResponseRedirect = {
77
+ kind: Kind,
78
+ endTime: redirect.endTime || 0,
79
+ startTime: redirect.startTime || 0,
80
+ url: redirect.url || '',
81
+ response: {
82
+ kind: ResponseKind,
83
+ status: 0,
84
+ },
85
+ };
86
+ if (redirect.response) {
87
+ const response = await HttpResponse.fromLegacy(redirect.response);
88
+ init.response = response.toJSON();
89
+ }
90
+ if (redirect.timings) {
91
+ init.timings = new RequestTime(redirect.timings).toJSON();
92
+ }
93
+ return new ResponseRedirect(init);
94
+ }
95
+
96
+ /**
97
+ * @param input The redirect definition used to restore the state.
98
+ */
99
+ constructor(input?: string|IResponseRedirect) {
100
+ let init: IResponseRedirect;
101
+ if (typeof input === 'string') {
102
+ init = JSON.parse(input);
103
+ } else if (typeof input === 'object') {
104
+ init = input;
105
+ } else {
106
+ init = {
107
+ kind: Kind,
108
+ endTime: 0,
109
+ startTime: 0,
110
+ url: '',
111
+ response: {
112
+ kind: ResponseKind,
113
+ status: 0,
114
+ },
115
+ };
116
+ }
117
+ this.new(init);
118
+ }
119
+
120
+ /**
121
+ * Creates a new redirect clearing anything that is so far defined.
122
+ *
123
+ * Note, this throws an error when the object is not an ARC redirect.
124
+ */
125
+ new(init: IResponseRedirect): void {
126
+ const { response, timings, startTime=0, endTime=0, url='', kind=Kind } = init;
127
+ this.kind = kind;
128
+ this.startTime = startTime;
129
+ this.endTime = endTime;
130
+ this.url = url;
131
+ this.response = new HttpResponse(response);
132
+ if (timings) {
133
+ this.timings = new RequestTime(timings);
134
+ } else {
135
+ this.timings = undefined;
136
+ }
137
+ }
138
+
139
+ toJSON(): IResponseRedirect {
140
+ const result: IResponseRedirect = {
141
+ kind: this.kind,
142
+ startTime: this.startTime,
143
+ endTime: this.endTime,
144
+ url: this.url,
145
+ response: {
146
+ kind: ResponseKind,
147
+ status: 0,
148
+ } as IHttpResponse,
149
+ };
150
+ if (this.response) {
151
+ result.response = this.response.toJSON();
152
+ }
153
+ if (this.timings) {
154
+ result.timings = this.timings.toJSON();
155
+ }
156
+ return result;
157
+ }
158
+ }
@@ -0,0 +1,37 @@
1
+ export const Kind = 'ARC#Revision';
2
+
3
+ /**
4
+ * The definition of a patch revision.
5
+ * The revision is created with the `json8-patch` library.
6
+ */
7
+ export interface IRevisionInfo {
8
+ /**
9
+ * The datastore key for this patch object.
10
+ */
11
+ id: string;
12
+ /**
13
+ * The key of the object which this patch was applied to.
14
+ */
15
+ key: string;
16
+ /**
17
+ * The kind of the object.
18
+ */
19
+ kind: string;
20
+ /**
21
+ * The timestamp when the patch was created.
22
+ */
23
+ created: number;
24
+ /**
25
+ * A flag determining that the revision is inactive.
26
+ * This may happen when a previous revision has been restored. This revision is then
27
+ * detached from the latest revision tree. It can be user to move forward in the history though.
28
+ *
29
+ * Implementations! Revisions should be removed from the storage when a new revision has been created
30
+ * that has diverged from the tree.
31
+ */
32
+ deleted?: boolean;
33
+ /**
34
+ * The `json8-patch` revisions object used to restore the previous state.
35
+ */
36
+ patch: any[];
37
+ }