@api-client/core 0.3.3 → 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 (176) hide show
  1. package/package.json +1 -1
  2. package/src/data/DataReader.ts +11 -0
  3. package/src/data/DataUtils.ts +108 -0
  4. package/src/data/JmesparthReader.ts +26 -0
  5. package/src/data/Json2Xml.ts +190 -0
  6. package/src/data/JsonReader.ts +41 -0
  7. package/src/data/PayloadPointer.ts +48 -0
  8. package/src/data/RequestDataExtractor.ts +133 -0
  9. package/src/data/UrlEncodedReader.ts +20 -0
  10. package/src/data/XmlReader.ts +103 -0
  11. package/src/events/BaseEvents.ts +259 -0
  12. package/src/events/CustomEvent.ts +27 -0
  13. package/src/events/EventTypes.ts +19 -0
  14. package/src/events/Events.ts +19 -0
  15. package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
  16. package/src/events/authorization/AuthorizationEvents.ts +61 -0
  17. package/src/events/cookies/CookieEventTypes.ts +13 -0
  18. package/src/events/cookies/CookieEvents.ts +157 -0
  19. package/src/events/encryption/EncryptionEventTypes.ts +4 -0
  20. package/src/events/encryption/EncryptionEvents.ts +51 -0
  21. package/src/events/environment/EnvironmentEventTypes.ts +3 -0
  22. package/src/events/environment/EnvironmentEvents.ts +24 -0
  23. package/src/events/models/ClientCertificateEvents.ts +87 -0
  24. package/src/events/models/ModelEventTypes.ts +47 -0
  25. package/src/events/models/ModelEvents.ts +7 -0
  26. package/src/events/models/ProjectEvents.ts +331 -0
  27. package/src/events/process/ProcessEventTypes.ts +5 -0
  28. package/src/events/process/ProcessEvents.ts +76 -0
  29. package/src/events/readme.md +22 -0
  30. package/src/events/reporting/ReportingEventTypes.ts +3 -0
  31. package/src/events/reporting/ReportingEvents.ts +28 -0
  32. package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
  33. package/src/events/telemetry/TelemetryEvents.ts +156 -0
  34. package/src/lib/cookies/Cookie.ts +312 -0
  35. package/src/lib/cookies/Cookies.ts +326 -0
  36. package/src/lib/cookies/Utils.ts +168 -0
  37. package/src/lib/headers/Headers.ts +219 -0
  38. package/src/lib/logging/DefaultLogger.ts +19 -0
  39. package/src/lib/logging/DummyLogger.ts +21 -0
  40. package/src/lib/logging/Logger.ts +16 -0
  41. package/src/lib/transformers/PayloadSerializer.ts +332 -0
  42. package/src/lib/transformers/Utils.ts +18 -0
  43. package/src/lib/uuid.ts +40 -0
  44. package/src/mocking/LegacyInterfaces.ts +52 -0
  45. package/src/mocking/LegacyMock.ts +37 -0
  46. package/src/mocking/legacy/Authorization.ts +39 -0
  47. package/src/mocking/legacy/Certificates.ts +145 -0
  48. package/src/mocking/legacy/Cookies.ts +51 -0
  49. package/src/mocking/legacy/HostRules.ts +43 -0
  50. package/src/mocking/legacy/Http.ts +236 -0
  51. package/src/mocking/legacy/HttpResponse.ts +106 -0
  52. package/src/mocking/legacy/RestApi.ts +68 -0
  53. package/src/mocking/legacy/Urls.ts +44 -0
  54. package/src/mocking/legacy/Variables.ts +53 -0
  55. package/src/models/ArcResponse.ts +166 -0
  56. package/src/models/Authorization.ts +481 -0
  57. package/src/models/AuthorizationData.ts +60 -0
  58. package/src/models/Backend.ts +107 -0
  59. package/src/models/ClientCertificate.ts +68 -0
  60. package/src/models/Environment.ts +279 -0
  61. package/src/models/ErrorResponse.ts +101 -0
  62. package/src/models/HistoryIndex.ts +76 -0
  63. package/src/models/HistoryRequest.ts +28 -0
  64. package/src/models/HostRule.ts +163 -0
  65. package/src/models/HttpCookie.ts +285 -0
  66. package/src/models/HttpProject.ts +1294 -0
  67. package/src/models/HttpProjectListItem.ts +23 -0
  68. package/src/models/HttpRequest.ts +124 -0
  69. package/src/models/HttpResponse.ts +143 -0
  70. package/src/models/License.ts +113 -0
  71. package/src/models/ProjectDefinitionProperty.ts +40 -0
  72. package/src/models/ProjectFolder.ts +439 -0
  73. package/src/models/ProjectItem.ts +135 -0
  74. package/src/models/ProjectParent.ts +113 -0
  75. package/src/models/ProjectRequest.ts +277 -0
  76. package/src/models/ProjectSchema.ts +202 -0
  77. package/src/models/Property.ts +423 -0
  78. package/src/models/Provider.ts +98 -0
  79. package/src/models/README.md +20 -0
  80. package/src/models/Request.ts +452 -0
  81. package/src/models/RequestActions.ts +163 -0
  82. package/src/models/RequestAuthorization.ts +115 -0
  83. package/src/models/RequestConfig.ts +317 -0
  84. package/src/models/RequestLog.ts +159 -0
  85. package/src/models/RequestTime.ts +108 -0
  86. package/src/models/RequestUiMeta.ts +258 -0
  87. package/src/models/RequestsSize.ts +65 -0
  88. package/src/models/ResponseAuthorization.ts +104 -0
  89. package/src/models/ResponseRedirect.ts +158 -0
  90. package/src/models/RevisionInfo.ts +37 -0
  91. package/src/models/SentRequest.ts +125 -0
  92. package/src/models/SerializablePayload.ts +68 -0
  93. package/src/models/Server.ts +153 -0
  94. package/src/models/Thing.ts +110 -0
  95. package/src/models/Url.ts +90 -0
  96. package/src/models/User.ts +120 -0
  97. package/src/models/WebApi.ts +234 -0
  98. package/src/models/WebApiIndex.ts +122 -0
  99. package/src/models/Workspace.ts +182 -0
  100. package/src/models/actions/Action.ts +213 -0
  101. package/src/models/actions/ActionView.ts +40 -0
  102. package/src/models/actions/Condition.ts +207 -0
  103. package/src/models/actions/ConditionView.ts +42 -0
  104. package/src/models/actions/Enums.ts +29 -0
  105. package/src/models/actions/RunnableAction.ts +144 -0
  106. package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
  107. package/src/models/actions/runnable/Runnable.ts +9 -0
  108. package/src/models/actions/runnable/SetCookieAction.ts +216 -0
  109. package/src/models/actions/runnable/SetVariableAction.ts +81 -0
  110. package/src/models/legacy/DataExport.ts +172 -0
  111. package/src/models/legacy/Normalizer.ts +110 -0
  112. package/src/models/legacy/actions/Actions.ts +269 -0
  113. package/src/models/legacy/authorization/Authorization.ts +572 -0
  114. package/src/models/legacy/models/ApiTypes.ts +202 -0
  115. package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
  116. package/src/models/legacy/models/AuthData.ts +17 -0
  117. package/src/models/legacy/models/ClientCertificate.ts +95 -0
  118. package/src/models/legacy/models/Cookies.ts +52 -0
  119. package/src/models/legacy/models/HostRule.ts +35 -0
  120. package/src/models/legacy/models/RestApi.ts +49 -0
  121. package/src/models/legacy/models/UrlHistory.ts +37 -0
  122. package/src/models/legacy/models/Variable.ts +43 -0
  123. package/src/models/legacy/models/base.d.ts +95 -0
  124. package/src/models/legacy/request/ArcRequest.ts +405 -0
  125. package/src/models/legacy/request/ArcResponse.ts +177 -0
  126. package/src/models/legacy/request/HistoryData.ts +47 -0
  127. package/src/models/legacy/request/Legacy.ts +45 -0
  128. package/src/models/legacy/request/RequestBody.ts +87 -0
  129. package/src/models/transformers/ArcDexieTransformer.ts +323 -0
  130. package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
  131. package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
  132. package/src/models/transformers/ArcPouchTransformer.ts +184 -0
  133. package/src/models/transformers/BaseTransformer.ts +116 -0
  134. package/src/models/transformers/ImportUtils.ts +141 -0
  135. package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
  136. package/src/models/transformers/LegacyExportProcessor.ts +252 -0
  137. package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
  138. package/src/models/transformers/PostmanDataTransformer.ts +50 -0
  139. package/src/models/transformers/PostmanTransformer.ts +106 -0
  140. package/src/models/transformers/PostmanV21Transformer.ts +311 -0
  141. package/src/models/transformers/PostmanV2Transformer.ts +308 -0
  142. package/src/models/transformers/har.ts +865 -0
  143. package/src/runtime/actions/ActionRunner.ts +83 -0
  144. package/src/runtime/actions/ConditionRunner.ts +194 -0
  145. package/src/runtime/actions/RunnableCondition.ts +57 -0
  146. package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
  147. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
  148. package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
  149. package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
  150. package/src/runtime/http-engine/ArcEngine.ts +1064 -0
  151. package/src/runtime/http-engine/Errors.ts +13 -0
  152. package/src/runtime/http-engine/FormData.ts +85 -0
  153. package/src/runtime/http-engine/HttpEngine.ts +874 -0
  154. package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
  155. package/src/runtime/http-engine/NodeEngine.ts +787 -0
  156. package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
  157. package/src/runtime/http-engine/PayloadSupport.ts +84 -0
  158. package/src/runtime/http-engine/RequestUtils.ts +164 -0
  159. package/src/runtime/http-engine/ntlm/Des.ts +345 -0
  160. package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
  161. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
  162. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
  163. package/src/runtime/modules/BasicAuthCache.ts +133 -0
  164. package/src/runtime/modules/ExecutionResponse.ts +4 -0
  165. package/src/runtime/modules/ModulesRegistry.ts +136 -0
  166. package/src/runtime/modules/RequestAuthorization.ts +110 -0
  167. package/src/runtime/modules/RequestCookies.ts +145 -0
  168. package/src/runtime/node/ProjectRunner.ts +275 -0
  169. package/src/runtime/node/RequestFactory.ts +422 -0
  170. package/src/runtime/node/VariablesStore.ts +25 -0
  171. package/src/runtime/store/StoreSdk.ts +838 -0
  172. package/src/runtime/variables/Cache.ts +53 -0
  173. package/src/runtime/variables/EvalFunctions.ts +132 -0
  174. package/src/runtime/variables/ProjectVariables.ts +6 -0
  175. package/src/runtime/variables/VariablesProcessor.ts +543 -0
  176. package/src/runtime/variables/VariablesTokenizer.ts +55 -0
@@ -0,0 +1,113 @@
1
+ import { DeleteCookieConfig } from '../../legacy/actions/Actions.js';
2
+ import { Runnable, IRunnable } from './Runnable.js';
3
+
4
+ export const Kind = 'ARC#DeleteCookieAction';
5
+
6
+ export interface IDeleteCookieAction extends IRunnable {
7
+ kind?: 'ARC#DeleteCookieAction';
8
+ /**
9
+ * When set it uses request URL instead of defined URL in the action.
10
+ */
11
+ useRequestUrl?: boolean;
12
+ /**
13
+ * An URL associated with the cookie.
14
+ * Only used when `useRequestUrl` is not `true`.
15
+ * Either `url` or `useRequestUrl` must be set for the action to be considered valid.
16
+ */
17
+ url?: string;
18
+ /**
19
+ * Name of the cookie to remove.
20
+ * When not set it removes all cookies.
21
+ */
22
+ name?: string;
23
+ }
24
+
25
+ export class DeleteCookieAction extends Runnable {
26
+ kind = Kind;
27
+ /**
28
+ * When set it uses request URL instead of defined URL in the action.
29
+ */
30
+ useRequestUrl?: boolean;
31
+ /**
32
+ * An URL associated with the cookie.
33
+ * Only used when `useRequestUrl` is not `true`.
34
+ * Either `url` or `useRequestUrl` must be set for the action to be considered valid.
35
+ */
36
+ url?: string;
37
+ /**
38
+ * Name of the cookie to remove.
39
+ * When not set it removes all cookies.
40
+ */
41
+ name?: string;
42
+
43
+ isValid(): boolean {
44
+ return !!this.useRequestUrl || !!this.url;
45
+ }
46
+
47
+ static fromLegacy(legacy: DeleteCookieConfig): DeleteCookieAction {
48
+ const init: IDeleteCookieAction = {
49
+ kind: Kind,
50
+ name: legacy.name,
51
+ };
52
+ if (legacy.url) {
53
+ init.url = legacy.url;
54
+ }
55
+ if (typeof legacy.useRequestUrl === 'boolean') {
56
+ init.useRequestUrl = legacy.useRequestUrl;
57
+ }
58
+ if (legacy.removeAll) {
59
+ delete init.name;
60
+ }
61
+ return new DeleteCookieAction(init);
62
+ }
63
+
64
+ constructor(input?: string | IDeleteCookieAction) {
65
+ super();
66
+ let init: IDeleteCookieAction;
67
+ if (typeof input === 'string') {
68
+ init = JSON.parse(input);
69
+ } else if (typeof input === 'object') {
70
+ init = input;
71
+ } else {
72
+ init = {
73
+ kind: Kind,
74
+ };
75
+ }
76
+ this.new(init);
77
+ }
78
+
79
+ new(init: IDeleteCookieAction): void {
80
+ const { useRequestUrl, url, name } = init;
81
+ if (typeof useRequestUrl === 'boolean') {
82
+ this.useRequestUrl = useRequestUrl;
83
+ } else {
84
+ this.useRequestUrl = undefined;
85
+ }
86
+ if (url) {
87
+ this.url = url;
88
+ } else {
89
+ this.url = undefined;
90
+ }
91
+ if (name) {
92
+ this.name = name;
93
+ } else {
94
+ this.name = undefined;
95
+ }
96
+ }
97
+
98
+ toJSON(): IDeleteCookieAction {
99
+ const result: IDeleteCookieAction = {
100
+ kind: Kind,
101
+ };
102
+ if (this.url) {
103
+ result.url = this.url;
104
+ }
105
+ if (this.name) {
106
+ result.name = this.name;
107
+ }
108
+ if (typeof this.useRequestUrl === 'boolean') {
109
+ result.useRequestUrl = this.useRequestUrl;
110
+ }
111
+ return result;
112
+ }
113
+ }
@@ -0,0 +1,9 @@
1
+ export interface IRunnable {
2
+ kind?: unknown;
3
+ }
4
+
5
+ export abstract class Runnable {
6
+ kind: unknown;
7
+ abstract isValid(): boolean;
8
+ abstract toJSON(): unknown;
9
+ }
@@ -0,0 +1,216 @@
1
+ import { SetCookieConfig } from '../../legacy/actions/Actions.js';
2
+ import { Runnable, IRunnable } from './Runnable.js';
3
+ import { IDataSource } from '../Condition.js';
4
+ import { RequestDataSourceEnum } from '../Enums.js';
5
+
6
+ export const Kind = 'ARC#SetCookieAction';
7
+
8
+ export interface ISetCookieAction extends IRunnable {
9
+ kind?: 'ARC#SetCookieAction';
10
+ /**
11
+ * Name of the cookie
12
+ */
13
+ name: string;
14
+ /**
15
+ * Source of the cookie value
16
+ */
17
+ source: IDataSource;
18
+ /**
19
+ * When set it uses request URL instead of defined URL in the action
20
+ */
21
+ useRequestUrl?: boolean;
22
+ /**
23
+ * An URL associated with the cookie
24
+ */
25
+ url?: string;
26
+ /**
27
+ * The cookie expiration time
28
+ */
29
+ expires?: string;
30
+ /**
31
+ * Whether the cookie is host only
32
+ */
33
+ hostOnly?: boolean;
34
+ /**
35
+ * Whether the cookie is HTTP only
36
+ */
37
+ httpOnly?: boolean;
38
+ /**
39
+ * Whether the cookie is HTTPS only
40
+ */
41
+ secure?: boolean;
42
+ /**
43
+ * Whether the cookie is a session cookie
44
+ */
45
+ session?: boolean;
46
+ }
47
+
48
+ export class SetCookieAction extends Runnable {
49
+ kind = Kind;
50
+ /**
51
+ * Name of the cookie
52
+ */
53
+ name = '';
54
+ /**
55
+ * Source of the cookie value
56
+ */
57
+ source: IDataSource = { source: RequestDataSourceEnum.url, };
58
+ /**
59
+ * When set it uses request URL instead of defined URL in the action
60
+ */
61
+ useRequestUrl?: boolean;
62
+ /**
63
+ * An URL associated with the cookie
64
+ */
65
+ url?: string;
66
+ /**
67
+ * The cookie expiration time
68
+ */
69
+ expires?: string;
70
+ /**
71
+ * Whether the cookie is host only
72
+ */
73
+ hostOnly?: boolean;
74
+ /**
75
+ * Whether the cookie is HTTP only
76
+ */
77
+ httpOnly?: boolean;
78
+ /**
79
+ * Whether the cookie is HTTPS only
80
+ */
81
+ secure?: boolean;
82
+ /**
83
+ * Whether the cookie is a session cookie
84
+ */
85
+ session?: boolean;
86
+
87
+ static fromLegacy(legacy: SetCookieConfig): SetCookieAction {
88
+ const source = ({ ...legacy.source } as unknown) as IDataSource;
89
+ // @ts-ignore
90
+ delete source.iterator;
91
+ // @ts-ignore
92
+ delete source.iteratorEnabled;
93
+ const init: ISetCookieAction = {
94
+ kind: Kind,
95
+ name: legacy.name,
96
+ source,
97
+ };
98
+ if (legacy.url) {
99
+ init.url = legacy.url;
100
+ }
101
+ if (typeof legacy.useRequestUrl === 'boolean') {
102
+ init.useRequestUrl = legacy.useRequestUrl;
103
+ }
104
+ if (legacy.expires) {
105
+ init.expires = legacy.expires;
106
+ }
107
+ if (typeof legacy.hostOnly === 'boolean') {
108
+ init.hostOnly = legacy.hostOnly;
109
+ }
110
+ if (typeof legacy.httpOnly === 'boolean') {
111
+ init.httpOnly = legacy.httpOnly;
112
+ }
113
+ if (typeof legacy.secure === 'boolean') {
114
+ init.secure = legacy.secure;
115
+ }
116
+ if (typeof legacy.session === 'boolean') {
117
+ init.session = legacy.session;
118
+ }
119
+ return new SetCookieAction(init);
120
+ }
121
+
122
+ constructor(input?: string | ISetCookieAction) {
123
+ super();
124
+ let init: ISetCookieAction;
125
+ if (typeof input === 'string') {
126
+ init = JSON.parse(input);
127
+ } else if (typeof input === 'object') {
128
+ init = input;
129
+ } else {
130
+ init = {
131
+ kind: Kind,
132
+ name: '',
133
+ source: { source: RequestDataSourceEnum.url, },
134
+ };
135
+ }
136
+ this.new(init);
137
+ }
138
+
139
+ new(init: ISetCookieAction): void {
140
+ const { source={ source: RequestDataSourceEnum.url, }, name, useRequestUrl, url, expires, hostOnly, httpOnly, secure, session } = init;
141
+ this.source = source;
142
+ this.name = name;
143
+ if (typeof useRequestUrl === 'boolean') {
144
+ this.useRequestUrl = useRequestUrl;
145
+ }
146
+ if (url) {
147
+ this.url = url;
148
+ } else {
149
+ this.url = undefined;
150
+ }
151
+ if (expires) {
152
+ this.expires = expires;
153
+ } else {
154
+ this.expires = undefined;
155
+ }
156
+ if (typeof hostOnly === 'boolean') {
157
+ this.hostOnly = hostOnly;
158
+ } else {
159
+ this.hostOnly = undefined;
160
+ }
161
+ if (typeof httpOnly === 'boolean') {
162
+ this.httpOnly = httpOnly;
163
+ } else {
164
+ this.httpOnly = undefined;
165
+ }
166
+ if (typeof secure === 'boolean') {
167
+ this.secure = secure;
168
+ } else {
169
+ this.secure = undefined;
170
+ }
171
+ if (typeof session === 'boolean') {
172
+ this.session = session;
173
+ } else {
174
+ this.session = undefined;
175
+ }
176
+ }
177
+
178
+ toJSON(): ISetCookieAction {
179
+ const result: ISetCookieAction = {
180
+ kind: Kind,
181
+ source: this.source,
182
+ name: this.name,
183
+ };
184
+ if (this.url) {
185
+ result.url = this.url;
186
+ }
187
+ if (this.expires) {
188
+ result.expires = this.expires;
189
+ }
190
+ if (typeof this.useRequestUrl === 'boolean') {
191
+ result.useRequestUrl = this.useRequestUrl;
192
+ }
193
+ if (typeof this.hostOnly === 'boolean') {
194
+ result.hostOnly = this.hostOnly;
195
+ }
196
+ if (typeof this.httpOnly === 'boolean') {
197
+ result.httpOnly = this.httpOnly;
198
+ }
199
+ if (typeof this.secure === 'boolean') {
200
+ result.secure = this.secure;
201
+ }
202
+ if (typeof this.session === 'boolean') {
203
+ result.session = this.session;
204
+ }
205
+ return result;
206
+ }
207
+
208
+ isValid(): boolean {
209
+ const hasTarget = !!this.useRequestUrl || !!this.url;
210
+ if (!hasTarget) {
211
+ return hasTarget;
212
+ }
213
+ const { source } = this.source;
214
+ return !!source;
215
+ }
216
+ }
@@ -0,0 +1,81 @@
1
+ import { SetVariableConfig } from '../../legacy/actions/Actions.js';
2
+ import { Runnable, IRunnable } from './Runnable.js';
3
+ import { IDataSource } from '../Condition.js';
4
+ import { RequestDataSourceEnum } from '../Enums.js';
5
+
6
+ export const Kind = 'ARC#SetVariableAction';
7
+
8
+ export interface ISetVariableAction extends IRunnable {
9
+ kind?: 'ARC#SetVariableAction';
10
+ /**
11
+ * Name of the variable to set
12
+ */
13
+ name: string;
14
+ /**
15
+ * Source of the cookie value
16
+ */
17
+ source: IDataSource;
18
+ }
19
+
20
+ export class SetVariableAction extends Runnable {
21
+ kind = Kind;
22
+ /**
23
+ * Name of the variable to set
24
+ */
25
+ name = '';
26
+ /**
27
+ * Source of the cookie value
28
+ */
29
+ source: IDataSource = { source: RequestDataSourceEnum.url, };
30
+
31
+ static fromLegacy(legacy: SetVariableConfig): SetVariableAction {
32
+ const source = ({ ...legacy.source } as unknown) as IDataSource;
33
+ // @ts-ignore
34
+ delete source.iterator;
35
+ // @ts-ignore
36
+ delete source.iteratorEnabled;
37
+ const init: ISetVariableAction = {
38
+ kind: Kind,
39
+ name: legacy.name,
40
+ source,
41
+ };
42
+ return new SetVariableAction(init);
43
+ }
44
+
45
+ constructor(input?: string | ISetVariableAction) {
46
+ super();
47
+ let init: ISetVariableAction;
48
+ if (typeof input === 'string') {
49
+ init = JSON.parse(input);
50
+ } else if (typeof input === 'object') {
51
+ init = input;
52
+ } else {
53
+ init = {
54
+ kind: Kind,
55
+ name: '',
56
+ source: { source: RequestDataSourceEnum.url, },
57
+ };
58
+ }
59
+ this.new(init);
60
+ }
61
+
62
+ new(init: ISetVariableAction): void {
63
+ const { source={ source: RequestDataSourceEnum.url, }, name, } = init;
64
+ this.kind = Kind;
65
+ this.source = source;
66
+ this.name = name;
67
+ }
68
+
69
+ toJSON(): ISetVariableAction {
70
+ const result: ISetVariableAction = {
71
+ kind: Kind,
72
+ source: this.source,
73
+ name: this.name,
74
+ };
75
+ return result;
76
+ }
77
+
78
+ isValid(): boolean {
79
+ return !!this.name && !!this.source;
80
+ }
81
+ }
@@ -0,0 +1,172 @@
1
+ import { ARCHistoryRequest, ARCSavedRequest, ArcBaseRequest } from './request/ArcRequest.js';
2
+ import { ArcLegacyProject, ARCProject } from './models/ArcLegacyProject.js';
3
+ import { ARCWebsocketUrlHistory, ARCUrlHistory } from './models/UrlHistory.js';
4
+ import { ARCHostRule } from './models/HostRule.js';
5
+ import { ARCVariable } from './models/Variable.js';
6
+ import { ARCAuthData } from './models/AuthData.js';
7
+ import { ARCCertificateIndex, Certificate, ARCRequestCertificate } from './models/ClientCertificate.js';
8
+ import { ARCCookie } from './models/Cookies.js';
9
+
10
+ /**
11
+ * @deprecated
12
+ */
13
+ export interface ExportArcHistoryRequest extends ARCHistoryRequest, ExportEntity {}
14
+ /**
15
+ * @deprecated
16
+ */
17
+ export interface ExportArcProjects extends ArcLegacyProject, ExportEntity {}
18
+ /**
19
+ * @deprecated
20
+ */
21
+ export interface ExportArcWebsocketUrl extends ARCWebsocketUrlHistory, ExportEntity {}
22
+ /**
23
+ * @deprecated
24
+ */
25
+ export interface ExportArcUrlHistory extends ARCUrlHistory, ExportEntity {}
26
+ /**
27
+ * @deprecated
28
+ */
29
+ export interface ExportArcHostRule extends ARCHostRule, ExportEntity {}
30
+ /**
31
+ * @deprecated
32
+ */
33
+ export interface ExportArcVariable extends ARCVariable, ExportEntity {}
34
+ /**
35
+ * @deprecated
36
+ */
37
+ export interface ExportArcAuthData extends ARCAuthData, ExportEntity {}
38
+ /**
39
+ * @deprecated
40
+ */
41
+ export interface ExportArcClientCertificateData extends ExportEntity, ARCCertificateIndex {
42
+ cert?: Certificate | Certificate[];
43
+ pKey?: Certificate | Certificate[];
44
+ }
45
+
46
+ /**
47
+ * @deprecated
48
+ */
49
+ export interface ExportEntity {
50
+ /**
51
+ * The object kind
52
+ */
53
+ kind?: string;
54
+ /**
55
+ * The original datastore key.
56
+ * Note that the `_id` and `_rev` are deleted.
57
+ */
58
+ key: string;
59
+ }
60
+
61
+ /**
62
+ * @deprecated
63
+ */
64
+ export interface ExportArcSavedRequest extends ARCSavedRequest, ExportEntity {}
65
+
66
+ /**
67
+ * @deprecated
68
+ */
69
+ export interface ArcExportObject {
70
+ createdAt: string;
71
+ version: string;
72
+ kind: string;
73
+ loadToWorkspace?: boolean;
74
+ /**
75
+ * When true the export object was created with a Electron based cookie storage.
76
+ */
77
+ electronCookies?: boolean;
78
+ requests?: ExportArcSavedRequest[];
79
+ history?: ExportArcHistoryRequest[];
80
+ projects?: ExportArcProjects[];
81
+ websocketurlhistory?: ExportArcWebsocketUrl[];
82
+ urlhistory?: ExportArcUrlHistory[];
83
+ clientcertificates?: ExportArcClientCertificateData[];
84
+ cookies?: ExportArcCookie[];
85
+ hostrules?: ExportArcHostRule[];
86
+ variables?: ExportArcVariable[];
87
+ authdata?: ExportArcAuthData[];
88
+ }
89
+
90
+ /**
91
+ * @deprecated
92
+ */
93
+ export interface ExportArcCookie extends ARCCookie {
94
+ /**
95
+ * The object kind
96
+ */
97
+ kind: string;
98
+ /**
99
+ * Datastore ID if a data store other than Electron was used.
100
+ */
101
+ key?: string;
102
+ }
103
+
104
+ /**
105
+ * @deprecated
106
+ */
107
+ export interface EncryptionOptions {
108
+ /**
109
+ * When set it encrypts the data before export.
110
+ * This library does not support any particular encryption. It dispatches
111
+ * `encryptionencode` to request for data encryption.
112
+ */
113
+ encrypt?: boolean;
114
+ /**
115
+ * Passphrase to use to encode the data.
116
+ */
117
+ passphrase?: string;
118
+ }
119
+
120
+ /**
121
+ * @deprecated
122
+ */
123
+ export interface ExportOptions extends EncryptionOptions {
124
+ /**
125
+ * Name of the export provider.
126
+ * ARC supports Google Drive (`drive`) and `file` providers at the moment.
127
+ */
128
+ provider: string;
129
+
130
+ /**
131
+ * Adds flag to the export file to skip import table and storing the data
132
+ * to the data store when opening the file.
133
+ */
134
+ skipImport?: boolean;
135
+
136
+ /**
137
+ * Sets the `kind` property of export object.
138
+ */
139
+ kind?: string;
140
+ }
141
+
142
+ /**
143
+ * @deprecated
144
+ */
145
+ export interface ExportOptionsInternal extends ExportOptions {
146
+ /**
147
+ * The application version used to generate the export
148
+ */
149
+ appVersion: string;
150
+ }
151
+
152
+ export interface ArcExportProcessedData {
153
+ key: keyof ArcNativeDataExport;
154
+ data: any[];
155
+ }
156
+ export interface ArcExportClientCertificateData {
157
+ item: ARCCertificateIndex;
158
+ data: ARCRequestCertificate;
159
+ }
160
+
161
+ export interface ArcNativeDataExport {
162
+ authdata?: boolean | ARCAuthData[];
163
+ clientcertificates?: boolean;
164
+ cookies?: boolean | ARCCookie[];
165
+ history?: boolean | ARCHistoryRequest[];
166
+ hostrules?: boolean | ARCHostRule[];
167
+ projects?: boolean | ARCProject[];
168
+ requests?: boolean | (ARCSavedRequest | ArcBaseRequest | ARCHistoryRequest)[];
169
+ variables?: boolean | ARCVariable[];
170
+ websocketurlhistory?: boolean | ARCWebsocketUrlHistory[];
171
+ urlhistory?: boolean | ARCUrlHistory[];
172
+ }
@@ -0,0 +1,110 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { ARCHistoryRequest, ARCSavedRequest } from './request/ArcRequest.js';
3
+ import { TransformedPayload as LegacyTransformedPayload } from './request/ArcResponse.js';
4
+ import { IRequestAuthorization, Kind as AuthKind } from '../RequestAuthorization.js';
5
+ import { hasBuffer } from '../../lib/transformers/PayloadSerializer.js';
6
+
7
+ export class Normalizer {
8
+ static normalizeRequest(request: unknown): ARCHistoryRequest | ARCSavedRequest | undefined {
9
+ if (!request) {
10
+ return undefined;
11
+ }
12
+ const typed = { ...request as object } as any;
13
+ if (typed.legacyProject) {
14
+ const saved = typed as ARCSavedRequest;
15
+ if (!saved.projects) {
16
+ saved.projects = [];
17
+ }
18
+ saved.projects[saved.projects.length] = typed.legacyProject;
19
+ delete typed.legacyProject;
20
+ }
21
+ const skipKeys = ['_id', '_rev', '_deleted'];
22
+ Object.keys(typed).forEach((key) => {
23
+ if (key[0] === '_' && skipKeys.indexOf(key) === -1) {
24
+ delete typed[key];
25
+ }
26
+ });
27
+ if (!typed.created) {
28
+ typed.created = Date.now();
29
+ }
30
+ if (!typed.updated) {
31
+ typed.updated = typed.created;
32
+ }
33
+ if (!typed.midnight) {
34
+ const day = new Date(typed.updated);
35
+ day.setHours(0, 0, 0, 0);
36
+ typed.midnight = day.getTime();
37
+ }
38
+
39
+ if (!typed.type) {
40
+ if (typed.name) {
41
+ typed.type = 'saved';
42
+ } else {
43
+ typed.type = 'history';
44
+ }
45
+ } else if (typed.type === 'drive' || typed.type === 'google-drive') {
46
+ typed.type = 'saved';
47
+ }
48
+ if (typed.type === 'history' && !typed._id) {
49
+ typed._id = Normalizer.generateHistoryId(typed);
50
+ }
51
+
52
+ return Normalizer.normalizeAuthorization(typed as ARCHistoryRequest | ARCSavedRequest);
53
+ }
54
+
55
+ static generateHistoryId(request: ARCHistoryRequest): string {
56
+ const { method, url } = request;
57
+ const d = new Date();
58
+ d.setHours(0, 0, 0, 0);
59
+ const time = d.getTime();
60
+ const encUrl = encodeURIComponent(url);
61
+ return `${time}/${encUrl}/${method}`;
62
+ }
63
+
64
+ static normalizeAuthorization<T>(request: T): T {
65
+ const typed = request as any;
66
+ const { auth = {}, authType } = typed;
67
+ if (!authType) {
68
+ return request;
69
+ }
70
+ const requestAuth: IRequestAuthorization = {
71
+ config: auth,
72
+ enabled: true,
73
+ type: authType,
74
+ valid: true,
75
+ kind: AuthKind,
76
+ };
77
+ const copy = { ...typed };
78
+ copy.authorization = [requestAuth];
79
+ delete copy.auth;
80
+ delete copy.authType;
81
+ return copy;
82
+ }
83
+
84
+ /**
85
+ * Transforms the `TransformedPayload` object to its original data type.
86
+ */
87
+ static restoreTransformedPayload(body: string | ArrayBuffer | Buffer | LegacyTransformedPayload): string | Buffer | ArrayBuffer | undefined {
88
+ if (!body) {
89
+ return body;
90
+ }
91
+ if (typeof body === 'string') {
92
+ return body;
93
+ }
94
+ if (hasBuffer && body instanceof Buffer) {
95
+ return body;
96
+ }
97
+ if (body instanceof ArrayBuffer) {
98
+ return body;
99
+ }
100
+ const typed = body as LegacyTransformedPayload;
101
+ if (typed.type === 'ArrayBuffer' || (typed.type === 'Buffer' && !hasBuffer)) {
102
+ const { buffer } = new Uint8Array(typed.data);
103
+ return buffer;
104
+ }
105
+ if (hasBuffer && typed.type === 'Buffer') {
106
+ return Buffer.from(typed.data);
107
+ }
108
+ return undefined;
109
+ }
110
+ }