@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,213 @@
1
+ import { IActions } from './runnable/index.js';
2
+ import { Runnable, IRunnable } from './runnable/Runnable.js';
3
+ import { Kind as DeleteCookieKind, DeleteCookieAction, IDeleteCookieAction } from './runnable/DeleteCookieAction.js';
4
+ import { Kind as SetCookieKind, SetCookieAction, ISetCookieAction } from './runnable/SetCookieAction.js';
5
+ import { Kind as SetVariableKind, SetVariableAction, ISetVariableAction } from './runnable/SetVariableAction.js';
6
+ import { Action as LegacyAction, SetCookieConfig, SetVariableConfig, DeleteCookieConfig } from '../legacy/actions/Actions.js';
7
+
8
+ export const Kind = 'ARC#Action';
9
+
10
+ /**
11
+ * An interface representing a single action.
12
+ */
13
+ export interface IAction {
14
+ kind?: 'ARC#Action';
15
+ /**
16
+ * Action name.
17
+ */
18
+ name?: string;
19
+ /**
20
+ * Whether the action is enabled.
21
+ * An action is enabled by default.
22
+ * @default true
23
+ */
24
+ enabled?: boolean;
25
+ /**
26
+ * Action priority. The higher number the higher priority of execution.
27
+ */
28
+ priority?: number;
29
+ /**
30
+ * The action configuration. The schema depends on the action type.
31
+ */
32
+ config?: unknown;
33
+ /**
34
+ * Whether or not the action is executed synchronously to request / response
35
+ */
36
+ sync?: boolean;
37
+ /**
38
+ * Whether or not the request should fail when the action fails.
39
+ */
40
+ failOnError?: boolean;
41
+ }
42
+
43
+ export class Action {
44
+ kind = Kind;
45
+ /**
46
+ * Action name.
47
+ */
48
+ name?: string;
49
+ /**
50
+ * Whether the action is enabled.
51
+ */
52
+ enabled?: boolean;
53
+ /**
54
+ * Action priority. The higher number the higher priority of execution.
55
+ */
56
+ priority?: number;
57
+ /**
58
+ * Action configuration
59
+ */
60
+ config?: Runnable;
61
+ /**
62
+ * Whether or not the action is executed synchronously to request / response
63
+ */
64
+ sync?: boolean;
65
+ /**
66
+ * Whether or not the request should fail when the action fails.
67
+ */
68
+ failOnError?: boolean;
69
+
70
+ static fromLegacy(item: LegacyAction): Action {
71
+ const { priority, config, enabled, failOnError, name, sync } = item;
72
+ let newConfig: IRunnable | undefined;
73
+ switch (name) {
74
+ case 'set-cookie': newConfig = SetCookieAction.fromLegacy(config as SetCookieConfig).toJSON(); break;
75
+ case 'set-variable': newConfig = SetVariableAction.fromLegacy(config as SetVariableConfig); break;
76
+ case 'delete-cookie': newConfig = DeleteCookieAction.fromLegacy(config as DeleteCookieConfig); break;
77
+ }
78
+
79
+ const init: IAction = {
80
+ kind: Kind,
81
+ priority,
82
+ };
83
+ if (typeof enabled === 'boolean') {
84
+ init.enabled = enabled;
85
+ }
86
+ if (typeof failOnError === 'boolean') {
87
+ init.failOnError = failOnError;
88
+ }
89
+ if (typeof sync === 'boolean') {
90
+ init.sync = sync;
91
+ }
92
+ if (typeof name === 'string') {
93
+ init.name = name;
94
+ }
95
+ if (newConfig) {
96
+ init.config = newConfig;
97
+ }
98
+ return new Action(init);
99
+ }
100
+
101
+ /**
102
+ * Creates a default configuration of an action
103
+ */
104
+ static defaultAction(): Action {
105
+ const init: IAction = {
106
+ name: 'New action',
107
+ failOnError: false,
108
+ priority: 0,
109
+ sync: false,
110
+ enabled: true,
111
+ };
112
+ return new Action(init);
113
+ }
114
+
115
+ constructor(input?: string | IAction) {
116
+ let init: IAction;
117
+ if (typeof input === 'string') {
118
+ init = JSON.parse(input);
119
+ } else if (typeof input === 'object') {
120
+ init = input;
121
+ } else {
122
+ init = {
123
+ kind: Kind,
124
+ };
125
+ }
126
+ this.new(init);
127
+ }
128
+
129
+ new(init: IAction): void {
130
+ const { name, enabled, priority, sync, failOnError, config } = init;
131
+ this.kind = Kind;
132
+ if (name) {
133
+ this.name = name;
134
+ } else {
135
+ this.name = undefined;
136
+ }
137
+ if (typeof enabled === 'boolean') {
138
+ this.enabled = enabled;
139
+ } else {
140
+ this.enabled = undefined;
141
+ }
142
+ if (typeof sync === 'boolean') {
143
+ this.sync = sync;
144
+ } else {
145
+ this.sync = undefined;
146
+ }
147
+ if (typeof failOnError === 'boolean') {
148
+ this.failOnError = failOnError;
149
+ } else {
150
+ this.failOnError = undefined;
151
+ }
152
+ if (typeof priority === 'number') {
153
+ this.priority = priority;
154
+ } else {
155
+ this.priority = undefined;
156
+ }
157
+ if (config) {
158
+ this.setConfig(config);
159
+ } else {
160
+ this.config = undefined;
161
+ }
162
+ }
163
+
164
+ toJSON(): IAction {
165
+ const result: IAction = {
166
+ kind: Kind,
167
+ };
168
+ if (this.name) {
169
+ result.name = this.name;
170
+ }
171
+ if (this.config) {
172
+ result.config = this.config.toJSON() as IActions;
173
+ }
174
+ if (typeof this.enabled === 'boolean') {
175
+ result.enabled = this.enabled;
176
+ }
177
+ if (typeof this.sync === 'boolean') {
178
+ result.sync = this.sync;
179
+ }
180
+ if (typeof this.failOnError === 'boolean') {
181
+ result.failOnError = this.failOnError;
182
+ }
183
+ if (typeof this.priority === 'number') {
184
+ result.priority = this.priority;
185
+ }
186
+ return result;
187
+ }
188
+
189
+ setConfig(config: unknown): void {
190
+ const { kind } = config as IRunnable;
191
+ switch (kind) {
192
+ case DeleteCookieKind: this.config = new DeleteCookieAction(config as IDeleteCookieAction); break;
193
+ case SetCookieKind: this.config = new SetCookieAction(config as ISetCookieAction); break;
194
+ case SetVariableKind: this.config = new SetVariableAction(config as ISetVariableAction); break;
195
+ default: throw new Error(`Unknown action config.`)
196
+ }
197
+ }
198
+
199
+ /**
200
+ * The sort function for actions to sort them for the execution order.
201
+ */
202
+ static sortActions(a: Action, b: Action): number {
203
+ const { priority: p1=0 } = a;
204
+ const { priority: p2=0 } = b;
205
+ if (p1 > p2) {
206
+ return 1;
207
+ }
208
+ if (p2 > p1) {
209
+ return -1;
210
+ }
211
+ return 0;
212
+ }
213
+ }
@@ -0,0 +1,40 @@
1
+ export interface IActionView {
2
+ /**
3
+ * Whether the action is "opened" in the editor UI.
4
+ */
5
+ opened?: boolean;
6
+ }
7
+
8
+ export class ActionView {
9
+ /**
10
+ * Whether the action is "opened" in the editor UI.
11
+ */
12
+ opened?: boolean;
13
+
14
+ constructor(input?: string|IActionView) {
15
+ let init: IActionView;
16
+ if (typeof input === 'string') {
17
+ init = JSON.parse(input);
18
+ } else if (typeof input === 'object') {
19
+ init = input;
20
+ } else {
21
+ init = {
22
+ opened: false,
23
+ };
24
+ }
25
+ this.new(init);
26
+ }
27
+
28
+ new(init: IActionView): void {
29
+ const { opened=false } = init;
30
+ this.opened = opened;
31
+ }
32
+
33
+ toJSON(): IActionView {
34
+ const result: IActionView = {};
35
+ if (typeof this.opened === 'boolean') {
36
+ result.opened = this.opened;
37
+ }
38
+ return result;
39
+ }
40
+ }
@@ -0,0 +1,207 @@
1
+ import { ActionTypeEnum, RequestDataSourceEnum, ResponseDataSourceEnum, OperatorEnum } from './Enums.js';
2
+ import { Condition as LegacyCondition } from '../legacy/actions/Actions.js';
3
+
4
+ export const Kind = 'ARC#Condition';
5
+
6
+ /**
7
+ * A base interface describing a configuration to extract data from a request or a response.
8
+ */
9
+ export interface IDataSource {
10
+ /**
11
+ * The main data source. Either the request or the response object.
12
+ * This is required when the `source` is not equal to `value. In this case it is ignored
13
+ */
14
+ type?: ActionTypeEnum;
15
+ /**
16
+ * Source of the data.
17
+ */
18
+ source: RequestDataSourceEnum | ResponseDataSourceEnum | 'value';
19
+ /**
20
+ * The path to the data.
21
+ * For JSON value use https://jmespath.org/ syntax.
22
+ * For XML use xpath.
23
+ * For any other use a simple path to the data separated by dot (e.g. headers.content-type)
24
+ */
25
+ path?: string;
26
+ /**
27
+ * Only used when the `source` is `value`. The data extraction always returns this value.
28
+ */
29
+ value?: string;
30
+ }
31
+
32
+ /**
33
+ * Describes action's condition configuration.
34
+ */
35
+ export interface ICondition extends IDataSource {
36
+ kind: 'ARC#Condition',
37
+ /**
38
+ * The comparison operator.
39
+ */
40
+ operator?: OperatorEnum;
41
+ /**
42
+ * Whether the condition always pass.
43
+ * The condition is not really checked, values can be empty. The condition check always returns `true`.
44
+ */
45
+ alwaysPass?: boolean;
46
+ }
47
+
48
+ export class Condition {
49
+ kind = Kind;
50
+ /**
51
+ * The main data source. Either the request or the response object.
52
+ * This is required when the `source` is not equal to `value. In this case it is ignored
53
+ */
54
+ type?: ActionTypeEnum;
55
+ /**
56
+ * Source of the data.
57
+ */
58
+ source: RequestDataSourceEnum | ResponseDataSourceEnum | 'value' = RequestDataSourceEnum.url;
59
+ /**
60
+ * The path to the data.
61
+ * For JSON value use https://jmespath.org/ syntax.
62
+ * For XML use xpath.
63
+ * For any other use a simple path to the data separated by dot (e.g. headers.content-type)
64
+ */
65
+ path?: string;
66
+ /**
67
+ * Only used when the `source` is `value`. The data extraction always returns this value.
68
+ */
69
+ value?: string;
70
+ /**
71
+ * The comparison operator.
72
+ */
73
+ operator?: OperatorEnum;
74
+ /**
75
+ * Whether the condition always pass.
76
+ * The condition is not really checked, values can be empty. The condition check always returns `true`.
77
+ */
78
+ alwaysPass?: boolean;
79
+
80
+ static defaultCondition(type=ActionTypeEnum.response): Condition {
81
+ const init: ICondition = {
82
+ kind: Kind,
83
+ type,
84
+ source: RequestDataSourceEnum.url,
85
+ operator: OperatorEnum.equal,
86
+ path: '',
87
+ alwaysPass: false,
88
+ };
89
+ return new Condition(init);
90
+ }
91
+
92
+ static fromLegacy(runnable: LegacyCondition): Condition {
93
+ const { source, alwaysPass, operator, path, predictedValue, type, value } = runnable;
94
+ const init: ICondition = {
95
+ kind: Kind,
96
+ source: source as RequestDataSourceEnum | ResponseDataSourceEnum | 'value',
97
+ };
98
+ if (typeof alwaysPass === 'boolean') {
99
+ init.alwaysPass = alwaysPass;
100
+ }
101
+ if (typeof path === 'string') {
102
+ init.path = path;
103
+ }
104
+ if (path === 'value') {
105
+ init.value = String(value);
106
+ } else {
107
+ init.value = String(predictedValue);
108
+ }
109
+ if (operator) {
110
+ switch (operator) {
111
+ case 'contains': init.operator = OperatorEnum.contains; break;
112
+ case 'equal': init.operator = OperatorEnum.equal; break;
113
+ case 'greater-than': init.operator = OperatorEnum.greaterThan; break;
114
+ case 'greater-than-equal': init.operator = OperatorEnum.greaterThanEqual; break;
115
+ case 'less-than': init.operator = OperatorEnum.lessThan; break;
116
+ case 'less-than-equal': init.operator = OperatorEnum.lessThanEqual; break;
117
+ case 'not-equal': init.operator = OperatorEnum.notEqual; break;
118
+ case 'regex': init.operator = OperatorEnum.regex; break;
119
+ }
120
+ }
121
+ if (type) {
122
+ switch (type) {
123
+ case 'request': init.type = ActionTypeEnum.request; break;
124
+ case 'response': init.type = ActionTypeEnum.response; break;
125
+ }
126
+ }
127
+ return new Condition(init);
128
+ }
129
+
130
+ static alwaysPass(type=ActionTypeEnum.request): Condition {
131
+ const init: ICondition = {
132
+ kind: Kind,
133
+ type,
134
+ source: 'value',
135
+ alwaysPass: true,
136
+ };
137
+ return new Condition(init);
138
+ }
139
+
140
+ constructor(input?: string | ICondition) {
141
+ let init: ICondition;
142
+ if (typeof input === 'string') {
143
+ init = JSON.parse(input);
144
+ } else if (typeof input === 'object') {
145
+ init = input;
146
+ } else {
147
+ init = {
148
+ kind: Kind,
149
+ source: RequestDataSourceEnum.url,
150
+ };
151
+ }
152
+ this.new(init);
153
+ }
154
+
155
+ new(init: ICondition): void {
156
+ const { source = RequestDataSourceEnum.url, alwaysPass, operator, path, type, value } = init;
157
+ this.source = source;
158
+ if (typeof alwaysPass === 'boolean') {
159
+ this.alwaysPass = alwaysPass;
160
+ } else {
161
+ this.alwaysPass = undefined;
162
+ }
163
+ if (operator) {
164
+ this.operator = operator;
165
+ } else {
166
+ this.operator = undefined;
167
+ }
168
+ if (typeof path === 'string') {
169
+ this.path = path;
170
+ } else {
171
+ this.path = undefined;
172
+ }
173
+ if (type) {
174
+ this.type = type;
175
+ } else {
176
+ this.type = undefined;
177
+ }
178
+ if (value) {
179
+ this.value = value;
180
+ } else {
181
+ this.value = undefined;
182
+ }
183
+ }
184
+
185
+ toJSON(): ICondition {
186
+ const result: ICondition = {
187
+ source: this.source,
188
+ kind: Kind,
189
+ };
190
+ if (this.type) {
191
+ result.type = this.type;
192
+ }
193
+ if (this.path) {
194
+ result.path = this.path;
195
+ }
196
+ if (this.value) {
197
+ result.value = this.value;
198
+ }
199
+ if (this.operator) {
200
+ result.operator = this.operator;
201
+ }
202
+ if (typeof this.alwaysPass === 'boolean') {
203
+ result.alwaysPass = this.alwaysPass;
204
+ }
205
+ return result;
206
+ }
207
+ }
@@ -0,0 +1,42 @@
1
+ export interface IConditionView {
2
+ /**
3
+ * Whether the condition editor is rendered in the "full" view
4
+ * instead of the summary.
5
+ */
6
+ opened?: boolean;
7
+ }
8
+
9
+ export class ConditionView {
10
+ /**
11
+ * Whether the condition editor is rendered in the "full" view
12
+ * instead of the summary.
13
+ */
14
+ opened?: boolean;
15
+
16
+ constructor(input?: string|IConditionView) {
17
+ let init: IConditionView;
18
+ if (typeof input === 'string') {
19
+ init = JSON.parse(input);
20
+ } else if (typeof input === 'object') {
21
+ init = input;
22
+ } else {
23
+ init = {
24
+ opened: false,
25
+ };
26
+ }
27
+ this.new(init);
28
+ }
29
+
30
+ new(init: IConditionView): void {
31
+ const { opened=false } = init;
32
+ this.opened = opened;
33
+ }
34
+
35
+ toJSON(): IConditionView {
36
+ const result: IConditionView = {};
37
+ if (typeof this.opened === 'boolean') {
38
+ result.opened = this.opened;
39
+ }
40
+ return result;
41
+ }
42
+ }
@@ -0,0 +1,29 @@
1
+ export enum ActionTypeEnum {
2
+ request = 'request',
3
+ response = 'response',
4
+ }
5
+
6
+ export enum OperatorEnum {
7
+ equal = "equal",
8
+ notEqual = "not-equal",
9
+ greaterThan = "greater-than",
10
+ greaterThanEqual = "greater-than-equal",
11
+ lessThan = "less-than",
12
+ lessThanEqual = "less-than-equal",
13
+ contains = "contains",
14
+ regex = "regex",
15
+ }
16
+
17
+ export enum RequestDataSourceEnum {
18
+ url = "url",
19
+ method = "method",
20
+ headers = "headers",
21
+ body = "body"
22
+ }
23
+
24
+ export enum ResponseDataSourceEnum {
25
+ url = "url",
26
+ status = "status",
27
+ headers = "headers",
28
+ body = "body"
29
+ }
@@ -0,0 +1,144 @@
1
+ import { ICondition, Condition } from './Condition.js';
2
+ import { IAction, Action } from './Action.js';
3
+ import { RunnableAction as LegacyRunnable } from '../legacy/actions/Actions.js';
4
+
5
+ export const Kind = 'ARC#RunnableAction';
6
+
7
+ /**
8
+ * An interface representing a runnable set of action in a condition.
9
+ * For the actions to be executed the condition first has to be met.
10
+ * The condition can be configured to always pass by setting the `alwaysPass` property.
11
+ */
12
+ export interface IRunnableAction {
13
+ kind?: typeof Kind;
14
+ /**
15
+ * The condition to be checked when executing the runnable,
16
+ */
17
+ condition: ICondition;
18
+ /**
19
+ * The list of actions to execute.
20
+ */
21
+ actions: IAction[];
22
+ /**
23
+ * Whether the entire runnable is enabled. This is checked before the condition is executed.
24
+ * An action is enabled by default.
25
+ */
26
+ enabled?: boolean;
27
+ }
28
+
29
+ export class RunnableAction {
30
+ kind = Kind;
31
+ /**
32
+ * The condition to be checked when executing the runnable,
33
+ */
34
+ condition: Condition = new Condition();
35
+ /**
36
+ * The list of actions to execute.
37
+ */
38
+ actions: Action[] = [];
39
+ /**
40
+ * Whether the entire runnable is enabled. This is checked before the condition is executed.
41
+ */
42
+ enabled?: boolean;
43
+
44
+ static fromLegacy(runnable: LegacyRunnable): RunnableAction {
45
+ const result = new RunnableAction();
46
+ result.fromLegacy(runnable);
47
+ return result;
48
+ }
49
+
50
+ constructor(input?: string | IRunnableAction) {
51
+ let init: IRunnableAction;
52
+ if (typeof input === 'string') {
53
+ init = JSON.parse(input);
54
+ } else if (typeof input === 'object') {
55
+ init = input;
56
+ } else {
57
+ init = {
58
+ kind: Kind,
59
+ condition: new Condition().toJSON(),
60
+ actions: [],
61
+ enabled: true,
62
+ };
63
+ }
64
+ if (init.kind === Kind) {
65
+ this.new(init);
66
+ } else {
67
+ this.fromLegacy((init as unknown) as LegacyRunnable);
68
+ }
69
+ }
70
+
71
+ new(init: IRunnableAction): void {
72
+ const { enabled, condition, actions } = init;
73
+ this.enabled = enabled;
74
+ if (condition) {
75
+ this.condition = new Condition(condition);
76
+ } else {
77
+ this.condition = new Condition();
78
+ }
79
+ if (Array.isArray(actions)) {
80
+ this.actions = actions.map(i => new Action(i));
81
+ } else {
82
+ this.actions = [];
83
+ }
84
+ }
85
+
86
+ toJSON(): IRunnableAction {
87
+ const result: IRunnableAction = {
88
+ condition: this.condition.toJSON(),
89
+ actions: this.actions.map(i => i.toJSON()),
90
+ kind: Kind,
91
+ };
92
+ if (typeof this.enabled === 'boolean') {
93
+ result.enabled = this.enabled;
94
+ }
95
+ return result;
96
+ }
97
+
98
+ fromLegacy(runnable: LegacyRunnable): void {
99
+ const { actions, condition, enabled } = runnable;
100
+ if (typeof enabled === 'boolean') {
101
+ this.enabled = enabled;
102
+ }
103
+ if (condition) {
104
+ this.condition = Condition.fromLegacy(condition);
105
+ } else {
106
+ this.condition = new Condition();
107
+ }
108
+ if (Array.isArray(actions) && actions.length) {
109
+ this.actions = actions.map(i => Action.fromLegacy(i));
110
+ } else {
111
+ this.actions = [];
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Adds a new action to the list of runnable action.
117
+ *
118
+ * @param schema The schema of the action
119
+ * @returns Created instance of the action.
120
+ */
121
+ addAction(schema: IAction): Action;
122
+
123
+ /**
124
+ * Adds a new action to the list of runnable action.
125
+ *
126
+ * @param schema The instance of the action
127
+ * @returns The same instance of the action.
128
+ */
129
+ addAction(instance: Action): Action;
130
+
131
+ addAction(value: Action | IAction): Action {
132
+ if (!Array.isArray(this.actions)) {
133
+ this.actions = [];
134
+ }
135
+ let finalAction: Action;
136
+ if (value instanceof Action) {
137
+ finalAction = value;
138
+ } else {
139
+ finalAction = new Action(value);
140
+ }
141
+ this.actions.push(finalAction);
142
+ return finalAction;
143
+ }
144
+ }