@api-client/core 0.3.2 → 0.3.5

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 (205) hide show
  1. package/build/browser.d.ts +1 -0
  2. package/build/browser.js +1 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +1 -1
  5. package/build/index.js +1 -1
  6. package/build/index.js.map +1 -1
  7. package/build/src/models/ErrorResponse.d.ts +5 -4
  8. package/build/src/models/ErrorResponse.js +18 -5
  9. package/build/src/models/ErrorResponse.js.map +1 -1
  10. package/build/src/models/SerializableError.d.ts +30 -0
  11. package/build/src/models/SerializableError.js +63 -0
  12. package/build/src/models/SerializableError.js.map +1 -0
  13. package/build/src/runtime/http-engine/ArcEngine.js +8 -4
  14. package/build/src/runtime/http-engine/ArcEngine.js.map +1 -1
  15. package/build/src/runtime/http-engine/HttpEngine.d.ts +3 -3
  16. package/build/src/runtime/http-engine/HttpEngine.js +3 -3
  17. package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
  18. package/build/src/runtime/http-engine/NodeEngine.js +9 -4
  19. package/build/src/runtime/http-engine/NodeEngine.js.map +1 -1
  20. package/build/src/runtime/http-engine/NodeEngineDirect.js +8 -2
  21. package/build/src/runtime/http-engine/NodeEngineDirect.js.map +1 -1
  22. package/build/src/runtime/node/ProjectRunner.d.ts +2 -2
  23. package/build/src/runtime/node/ProjectRunner.js +9 -2
  24. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  25. package/build/src/runtime/store/StoreSdk.js +10 -15
  26. package/build/src/runtime/store/StoreSdk.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/data/DataReader.ts +11 -0
  29. package/src/data/DataUtils.ts +108 -0
  30. package/src/data/JmesparthReader.ts +26 -0
  31. package/src/data/Json2Xml.ts +190 -0
  32. package/src/data/JsonReader.ts +41 -0
  33. package/src/data/PayloadPointer.ts +48 -0
  34. package/src/data/RequestDataExtractor.ts +133 -0
  35. package/src/data/UrlEncodedReader.ts +20 -0
  36. package/src/data/XmlReader.ts +103 -0
  37. package/src/events/BaseEvents.ts +259 -0
  38. package/src/events/CustomEvent.ts +27 -0
  39. package/src/events/EventTypes.ts +19 -0
  40. package/src/events/Events.ts +19 -0
  41. package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
  42. package/src/events/authorization/AuthorizationEvents.ts +61 -0
  43. package/src/events/cookies/CookieEventTypes.ts +13 -0
  44. package/src/events/cookies/CookieEvents.ts +157 -0
  45. package/src/events/encryption/EncryptionEventTypes.ts +4 -0
  46. package/src/events/encryption/EncryptionEvents.ts +51 -0
  47. package/src/events/environment/EnvironmentEventTypes.ts +3 -0
  48. package/src/events/environment/EnvironmentEvents.ts +24 -0
  49. package/src/events/models/ClientCertificateEvents.ts +87 -0
  50. package/src/events/models/ModelEventTypes.ts +47 -0
  51. package/src/events/models/ModelEvents.ts +7 -0
  52. package/src/events/models/ProjectEvents.ts +331 -0
  53. package/src/events/process/ProcessEventTypes.ts +5 -0
  54. package/src/events/process/ProcessEvents.ts +76 -0
  55. package/src/events/readme.md +22 -0
  56. package/src/events/reporting/ReportingEventTypes.ts +3 -0
  57. package/src/events/reporting/ReportingEvents.ts +28 -0
  58. package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
  59. package/src/events/telemetry/TelemetryEvents.ts +156 -0
  60. package/src/lib/cookies/Cookie.ts +312 -0
  61. package/src/lib/cookies/Cookies.ts +326 -0
  62. package/src/lib/cookies/Utils.ts +168 -0
  63. package/src/lib/headers/Headers.ts +219 -0
  64. package/src/lib/logging/DefaultLogger.ts +19 -0
  65. package/src/lib/logging/DummyLogger.ts +21 -0
  66. package/src/lib/logging/Logger.ts +16 -0
  67. package/src/lib/transformers/PayloadSerializer.ts +332 -0
  68. package/src/lib/transformers/Utils.ts +18 -0
  69. package/src/lib/uuid.ts +40 -0
  70. package/src/mocking/LegacyInterfaces.ts +52 -0
  71. package/src/mocking/LegacyMock.ts +37 -0
  72. package/src/mocking/legacy/Authorization.ts +39 -0
  73. package/src/mocking/legacy/Certificates.ts +145 -0
  74. package/src/mocking/legacy/Cookies.ts +51 -0
  75. package/src/mocking/legacy/HostRules.ts +43 -0
  76. package/src/mocking/legacy/Http.ts +236 -0
  77. package/src/mocking/legacy/HttpResponse.ts +106 -0
  78. package/src/mocking/legacy/RestApi.ts +68 -0
  79. package/src/mocking/legacy/Urls.ts +44 -0
  80. package/src/mocking/legacy/Variables.ts +53 -0
  81. package/src/models/ArcResponse.ts +166 -0
  82. package/src/models/Authorization.ts +481 -0
  83. package/src/models/AuthorizationData.ts +60 -0
  84. package/src/models/Backend.ts +107 -0
  85. package/src/models/ClientCertificate.ts +68 -0
  86. package/src/models/Environment.ts +279 -0
  87. package/src/models/ErrorResponse.ts +113 -0
  88. package/src/models/HistoryIndex.ts +76 -0
  89. package/src/models/HistoryRequest.ts +28 -0
  90. package/src/models/HostRule.ts +163 -0
  91. package/src/models/HttpCookie.ts +285 -0
  92. package/src/models/HttpProject.ts +1294 -0
  93. package/src/models/HttpProjectListItem.ts +23 -0
  94. package/src/models/HttpRequest.ts +124 -0
  95. package/src/models/HttpResponse.ts +143 -0
  96. package/src/models/License.ts +113 -0
  97. package/src/models/ProjectDefinitionProperty.ts +40 -0
  98. package/src/models/ProjectFolder.ts +439 -0
  99. package/src/models/ProjectItem.ts +135 -0
  100. package/src/models/ProjectParent.ts +113 -0
  101. package/src/models/ProjectRequest.ts +277 -0
  102. package/src/models/ProjectSchema.ts +202 -0
  103. package/src/models/Property.ts +423 -0
  104. package/src/models/Provider.ts +98 -0
  105. package/src/models/README.md +20 -0
  106. package/src/models/Request.ts +452 -0
  107. package/src/models/RequestActions.ts +163 -0
  108. package/src/models/RequestAuthorization.ts +115 -0
  109. package/src/models/RequestConfig.ts +317 -0
  110. package/src/models/RequestLog.ts +159 -0
  111. package/src/models/RequestTime.ts +108 -0
  112. package/src/models/RequestUiMeta.ts +258 -0
  113. package/src/models/RequestsSize.ts +65 -0
  114. package/src/models/ResponseAuthorization.ts +104 -0
  115. package/src/models/ResponseRedirect.ts +158 -0
  116. package/src/models/RevisionInfo.ts +37 -0
  117. package/src/models/SentRequest.ts +125 -0
  118. package/src/models/SerializableError.ts +80 -0
  119. package/src/models/SerializablePayload.ts +68 -0
  120. package/src/models/Server.ts +153 -0
  121. package/src/models/Thing.ts +110 -0
  122. package/src/models/Url.ts +90 -0
  123. package/src/models/User.ts +120 -0
  124. package/src/models/WebApi.ts +234 -0
  125. package/src/models/WebApiIndex.ts +122 -0
  126. package/src/models/Workspace.ts +182 -0
  127. package/src/models/actions/Action.ts +213 -0
  128. package/src/models/actions/ActionView.ts +40 -0
  129. package/src/models/actions/Condition.ts +207 -0
  130. package/src/models/actions/ConditionView.ts +42 -0
  131. package/src/models/actions/Enums.ts +29 -0
  132. package/src/models/actions/RunnableAction.ts +144 -0
  133. package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
  134. package/src/models/actions/runnable/Runnable.ts +9 -0
  135. package/src/models/actions/runnable/SetCookieAction.ts +216 -0
  136. package/src/models/actions/runnable/SetVariableAction.ts +81 -0
  137. package/src/models/legacy/DataExport.ts +172 -0
  138. package/src/models/legacy/Normalizer.ts +110 -0
  139. package/src/models/legacy/actions/Actions.ts +269 -0
  140. package/src/models/legacy/authorization/Authorization.ts +572 -0
  141. package/src/models/legacy/models/ApiTypes.ts +202 -0
  142. package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
  143. package/src/models/legacy/models/AuthData.ts +17 -0
  144. package/src/models/legacy/models/ClientCertificate.ts +95 -0
  145. package/src/models/legacy/models/Cookies.ts +52 -0
  146. package/src/models/legacy/models/HostRule.ts +35 -0
  147. package/src/models/legacy/models/RestApi.ts +49 -0
  148. package/src/models/legacy/models/UrlHistory.ts +37 -0
  149. package/src/models/legacy/models/Variable.ts +43 -0
  150. package/src/models/legacy/models/base.d.ts +95 -0
  151. package/src/models/legacy/request/ArcRequest.ts +405 -0
  152. package/src/models/legacy/request/ArcResponse.ts +177 -0
  153. package/src/models/legacy/request/HistoryData.ts +47 -0
  154. package/src/models/legacy/request/Legacy.ts +45 -0
  155. package/src/models/legacy/request/RequestBody.ts +87 -0
  156. package/src/models/transformers/ArcDexieTransformer.ts +323 -0
  157. package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
  158. package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
  159. package/src/models/transformers/ArcPouchTransformer.ts +184 -0
  160. package/src/models/transformers/BaseTransformer.ts +116 -0
  161. package/src/models/transformers/ImportUtils.ts +141 -0
  162. package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
  163. package/src/models/transformers/LegacyExportProcessor.ts +252 -0
  164. package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
  165. package/src/models/transformers/PostmanDataTransformer.ts +50 -0
  166. package/src/models/transformers/PostmanTransformer.ts +106 -0
  167. package/src/models/transformers/PostmanV21Transformer.ts +311 -0
  168. package/src/models/transformers/PostmanV2Transformer.ts +308 -0
  169. package/src/models/transformers/har.ts +865 -0
  170. package/src/runtime/actions/ActionRunner.ts +83 -0
  171. package/src/runtime/actions/ConditionRunner.ts +194 -0
  172. package/src/runtime/actions/RunnableCondition.ts +57 -0
  173. package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
  174. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
  175. package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
  176. package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
  177. package/src/runtime/http-engine/ArcEngine.ts +1068 -0
  178. package/src/runtime/http-engine/FormData.ts +85 -0
  179. package/src/runtime/http-engine/HttpEngine.ts +874 -0
  180. package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
  181. package/src/runtime/http-engine/NodeEngine.ts +792 -0
  182. package/src/runtime/http-engine/NodeEngineDirect.ts +482 -0
  183. package/src/runtime/http-engine/PayloadSupport.ts +84 -0
  184. package/src/runtime/http-engine/RequestUtils.ts +164 -0
  185. package/src/runtime/http-engine/ntlm/Des.ts +345 -0
  186. package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
  187. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
  188. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
  189. package/src/runtime/modules/BasicAuthCache.ts +133 -0
  190. package/src/runtime/modules/ExecutionResponse.ts +4 -0
  191. package/src/runtime/modules/ModulesRegistry.ts +136 -0
  192. package/src/runtime/modules/RequestAuthorization.ts +110 -0
  193. package/src/runtime/modules/RequestCookies.ts +145 -0
  194. package/src/runtime/node/ProjectRunner.ts +281 -0
  195. package/src/runtime/node/RequestFactory.ts +422 -0
  196. package/src/runtime/node/VariablesStore.ts +25 -0
  197. package/src/runtime/store/StoreSdk.ts +838 -0
  198. package/src/runtime/variables/Cache.ts +53 -0
  199. package/src/runtime/variables/EvalFunctions.ts +132 -0
  200. package/src/runtime/variables/ProjectVariables.ts +6 -0
  201. package/src/runtime/variables/VariablesProcessor.ts +543 -0
  202. package/src/runtime/variables/VariablesTokenizer.ts +55 -0
  203. package/build/src/runtime/http-engine/Errors.d.ts +0 -10
  204. package/build/src/runtime/http-engine/Errors.js +0 -14
  205. package/build/src/runtime/http-engine/Errors.js.map +0 -1
@@ -0,0 +1,19 @@
1
+ import { Logger } from './Logger.js';
2
+
3
+ export class DefaultLogger extends Logger {
4
+ warn(...args: unknown[]): void {
5
+ console.warn(...args);
6
+ }
7
+ info(...args: unknown[]): void {
8
+ console.info(...args);
9
+ }
10
+ error(...args: unknown[]): void {
11
+ console.error(...args);
12
+ }
13
+ log(...args: unknown[]): void {
14
+ console.log(...args);
15
+ }
16
+ debug(...args: unknown[]): void {
17
+ console.debug(...args);
18
+ }
19
+ }
@@ -0,0 +1,21 @@
1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ import { Logger } from './Logger.js';
4
+
5
+ export class DummyLogger extends Logger {
6
+ warn(...args: unknown[]): void {
7
+ // ...
8
+ }
9
+ info(...args: unknown[]): void {
10
+ // ...
11
+ }
12
+ error(...args: unknown[]): void {
13
+ // ...
14
+ }
15
+ log(...args: unknown[]): void {
16
+ // ...
17
+ }
18
+ debug(...args: unknown[]): void {
19
+ // ...
20
+ }
21
+ }
@@ -0,0 +1,16 @@
1
+ /* eslint-disable no-unused-vars */
2
+ export interface ILogger {
3
+ warn: (...args: unknown[]) => void;
4
+ info: (...args: unknown[]) => void;
5
+ error: (...args: unknown[]) => void;
6
+ log: (...args: unknown[]) => void;
7
+ debug: (...args: unknown[]) => void;
8
+ }
9
+
10
+ export abstract class Logger {
11
+ abstract warn(...args: unknown[]): void;
12
+ abstract info(...args: unknown[]): void;
13
+ abstract error(...args: unknown[]): void;
14
+ abstract log(...args: unknown[]): void;
15
+ abstract debug(...args: unknown[]): void;
16
+ }
@@ -0,0 +1,332 @@
1
+ import { blobToDataUrl } from './Utils.js';
2
+
3
+ export type PayloadTypes = 'string' | 'file' | 'blob' | 'buffer' | 'arraybuffer' | 'formdata' | 'x-www-form-urlencoded';
4
+ export type DeserializedPayload = string | Blob | File | FormData | Buffer | ArrayBuffer | undefined;
5
+
6
+ export interface IMultipartBody {
7
+ /**
8
+ * When true a this entry represent a file part
9
+ */
10
+ isFile: boolean;
11
+ /**
12
+ * The name of the filed
13
+ */
14
+ name: string;
15
+ /**
16
+ * Converted value
17
+ */
18
+ value: string;
19
+ /**
20
+ * A content type entered by the user to the text part of the text part input.
21
+ * This can only be set when `isFile` is false.
22
+ */
23
+ type?: string;
24
+ /**
25
+ * The original file name used with the part
26
+ */
27
+ fileName?: string;
28
+ /**
29
+ * Whether the parameter is enabled. Default to true.
30
+ */
31
+ enabled?: boolean;
32
+ }
33
+
34
+ /**
35
+ * Represents a payload that is safe to store in a data store.
36
+ * The `string` goes without any transformations.
37
+ * The `file` and the `blob` are data URLs encoded as string.
38
+ * The `buffer` and `arraybuffer` are UInt8Arrays.
39
+ */
40
+ export interface ISafePayload {
41
+ /**
42
+ * The type od the originating payload object.
43
+ */
44
+ type: PayloadTypes;
45
+ data: string | number[] | IMultipartBody[];
46
+ /**
47
+ * Optionally the original mime type of the payload.
48
+ * This is used with files.
49
+ */
50
+ mime?: string;
51
+ }
52
+ /**
53
+ * The request payload. When not a string then it has to go through a
54
+ * transformation from a store safe object to the original data object.
55
+ * For example, a file is stored as type 'file' and data with the file's data URL.
56
+ * A Buffer / ArrayBuffer is stored as type 'buffer' / 'arraybuffer' respectively
57
+ * with the `data` being an UInt8Array of the content.
58
+ */
59
+ export type Payload = string | ISafePayload;
60
+
61
+ export const hasFormData: boolean = typeof FormData === 'function';
62
+ export const hasBlob: boolean = typeof Blob === 'function';
63
+ export const hasBuffer: boolean = typeof Buffer === 'function';
64
+
65
+ export class PayloadSerializer {
66
+ /**
67
+ * Transforms the payload into a data store safe object.
68
+ */
69
+ static async serialize(payload: DeserializedPayload): Promise<ISafePayload | string | undefined> {
70
+ if (typeof payload === 'undefined' || payload === null) {
71
+ return undefined;
72
+ }
73
+ if (typeof payload === 'string') {
74
+ return payload;
75
+ }
76
+ if (hasBlob && payload instanceof Blob) {
77
+ return PayloadSerializer.stringifyBlob(payload);
78
+ }
79
+ if (hasBuffer && payload instanceof Buffer) {
80
+ return PayloadSerializer.stringifyBuffer(payload);
81
+ }
82
+ if (payload instanceof ArrayBuffer) {
83
+ return PayloadSerializer.stringifyArrayBuffer(payload);
84
+ }
85
+ if (hasFormData && payload instanceof FormData) {
86
+ try {
87
+ const result = await PayloadSerializer.stringifyFormData((payload as unknown) as Iterable<(string | File)[]>);
88
+ return result;
89
+ } catch (e: unknown) {
90
+ console.warn(`Unable to transform FormData: ${(e as Error).message}`);
91
+ }
92
+ }
93
+ return '';
94
+ }
95
+
96
+ /**
97
+ * Converts blob data to base64 string.
98
+ *
99
+ * @param blob File or blob object to be translated to string
100
+ * @return Promise resolved to a base64 string data from the file.
101
+ */
102
+ static async stringifyBlob(blob: Blob): Promise<ISafePayload> {
103
+ const typedFile = blob as File;
104
+ const data = await blobToDataUrl(blob);
105
+ const result: ISafePayload = {
106
+ type: 'blob',
107
+ data,
108
+ mime: typedFile.type,
109
+ };
110
+ return result;
111
+ }
112
+
113
+ /**
114
+ * When the passed argument is a NodeJS buffer it creates an object describing the buffer
115
+ * in a safe to store object.
116
+ *
117
+ * @returns The buffer metadata or undefined if the passed argument is not a Buffer.
118
+ */
119
+ static stringifyBuffer(payload: Buffer): ISafePayload | undefined {
120
+ if (typeof payload.copy === 'function') {
121
+ return {
122
+ type: 'buffer',
123
+ data: [...payload],
124
+ };
125
+ }
126
+ return undefined;
127
+ }
128
+
129
+ /**
130
+ * When the passed argument is an ArrayBuffer it creates an object describing the object in a safe to store object.
131
+ *
132
+ * @param {any} payload
133
+ * @returns {TransformedPayload|undefined} The buffer metadata or undefined if the passed argument is not an ArrayBuffer.
134
+ */
135
+ static stringifyArrayBuffer(payload: ArrayBuffer): ISafePayload | undefined {
136
+ if (payload.byteLength) {
137
+ const view = new Uint8Array(payload);
138
+ return {
139
+ type: 'arraybuffer',
140
+ data: Array.from(view),
141
+ };
142
+ }
143
+ return undefined;
144
+ }
145
+
146
+ /**
147
+ * Transforms the FormData object to a serialized object describing the data.
148
+ *
149
+ * @param payload A `FormData` object
150
+ * @return A promise resolved to a datastore safe entries.
151
+ */
152
+ static async stringifyFormData(payload: Iterable<(string | File)[]>): Promise<ISafePayload> {
153
+ const promises: Promise<IMultipartBody>[] = [];
154
+ for (const part of payload) {
155
+ promises.push(PayloadSerializer.serializeFormDataEntry(part[0] as string, part[1]));
156
+ }
157
+ const items = await Promise.all(promises);
158
+ return {
159
+ type: 'formdata',
160
+ data: items,
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Transforms a FormData entry into a safe-to-store text entry
166
+ *
167
+ * @param {string} name The part name
168
+ * @param {string|File} file The part value
169
+ * @return {Promise<IMultipartBody>} Transformed FormData part to a datastore safe entry.
170
+ */
171
+ static async serializeFormDataEntry(name: string, file: string | File): Promise<IMultipartBody> {
172
+ if (typeof file === 'string') {
173
+ // when adding an item to the FormData object without 3rd parameter of the append function
174
+ // then the value is a string.
175
+ return {
176
+ isFile: false,
177
+ name,
178
+ value: file,
179
+ enabled: true,
180
+ };
181
+ }
182
+
183
+ const value = await blobToDataUrl(file);
184
+ const part: IMultipartBody = {
185
+ isFile: false,
186
+ name,
187
+ value,
188
+ enabled: true,
189
+ };
190
+ if (file.name === 'blob') {
191
+ // ARC adds the "blob" filename when the content type is set on the editor.
192
+ // otherwise it wouldn't be possible to set the content type value.
193
+ part.type = file.type;
194
+ } else {
195
+ part.isFile = true;
196
+ part.fileName = file.name;
197
+ }
198
+ return part;
199
+ }
200
+
201
+ /**
202
+ * Restores the payload into its original format.
203
+ */
204
+ static async deserialize(payload: ISafePayload | string | undefined): Promise<DeserializedPayload> {
205
+ if (typeof payload === 'undefined' || payload === null) {
206
+ return undefined;
207
+ }
208
+ if (typeof payload === 'string') {
209
+ return payload;
210
+ }
211
+ if (hasBuffer && !hasBlob) {
212
+ // we are in the nodejs environment.
213
+ // We mostly gonna return a Buffer here.
214
+ switch (payload.type) {
215
+ case 'string': return payload.data as string;
216
+ case 'file':
217
+ case 'blob': return PayloadSerializer.deserializeBlobBuffer(payload.data as string);
218
+ case 'buffer': return PayloadSerializer.deserializeBuffer(payload.data as number[]);
219
+ case 'arraybuffer': return PayloadSerializer.deserializeArrayBufferBuffer(payload.data as number[]);
220
+ case 'formdata': return undefined;
221
+ default: return undefined;
222
+ }
223
+ }
224
+ switch (payload.type) {
225
+ case 'string': return payload.data as string;
226
+ case 'file':
227
+ case 'blob': return PayloadSerializer.deserializeBlob(payload.data as string);
228
+ case 'buffer': return PayloadSerializer.deserializeBuffer(payload.data as number[]);
229
+ case 'arraybuffer': return PayloadSerializer.deserializeArrayBuffer(payload.data as number[]);
230
+ case 'formdata': return PayloadSerializer.deserializeFormData(payload.data as IMultipartBody[]);
231
+ default: return undefined;
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Converts data-url string to blob
237
+ *
238
+ * @param dataUrl Data url from blob value.
239
+ * @return Restored blob value
240
+ */
241
+ static deserializeBlob(dataUrl: string): Blob | undefined {
242
+ const arr = dataUrl.split(',');
243
+ const matchedMime = arr[0].match(/:(.*?);/);
244
+ if (!matchedMime) {
245
+ return undefined;
246
+ }
247
+ const mime = matchedMime[1];
248
+ const bstr = atob(arr[1]);
249
+ let n = bstr.length;
250
+ const u8arr = new Uint8Array(n);
251
+ while (n--) {
252
+ u8arr[n] = bstr.charCodeAt(n);
253
+ }
254
+ return new Blob([u8arr], { type: mime });
255
+ }
256
+
257
+ /**
258
+ * Converts data-url string to blob
259
+ *
260
+ * @param dataUrl Data url from blob value.
261
+ * @return Restored blob value
262
+ */
263
+ static deserializeBlobBuffer(dataUrl: string): Buffer {
264
+ const arr = dataUrl.split(',');
265
+ const value = arr[1];
266
+ return Buffer.from(value, 'base64url');
267
+ }
268
+
269
+ /**
270
+ * Converts UInt8Array to a Buffer.
271
+ *
272
+ * @param data Previously serialized buffer.
273
+ * @return Restored blob value
274
+ */
275
+ static deserializeBuffer(data: number[]): Buffer {
276
+ return Buffer.from(data);
277
+ }
278
+
279
+ /**
280
+ * Converts UInt8Array to an ArrayBuffer.
281
+ *
282
+ * @param data Previously serialized buffer.
283
+ */
284
+ static deserializeArrayBuffer(data: number[]): ArrayBuffer {
285
+ const { buffer } = new Uint8Array(data);
286
+ return buffer;
287
+ }
288
+
289
+ /**
290
+ * Converts UInt8Array to a Buffer.
291
+ *
292
+ * @param data Previously serialized buffer.
293
+ */
294
+ static deserializeArrayBufferBuffer(data: number[]): Buffer {
295
+ const ab = this.deserializeArrayBuffer(data);
296
+ return Buffer.from(ab);
297
+ }
298
+
299
+ /**
300
+ * Deserializes FormData from ARC data model.
301
+ *
302
+ * @param {IMultipartBody[]} model ARC model for multipart.
303
+ * @return {FormData} Restored form data
304
+ */
305
+ static deserializeFormData(parts: IMultipartBody[]): FormData {
306
+ const fd = new FormData();
307
+ if (!Array.isArray(parts) || !parts.length) {
308
+ return fd;
309
+ }
310
+ parts.forEach((part) => {
311
+ const { isFile, name, value, type, fileName, enabled } = part;
312
+ if (enabled === false) {
313
+ return;
314
+ }
315
+ let blob;
316
+ if (isFile) {
317
+ blob = PayloadSerializer.deserializeBlob(value);
318
+ if (blob) {
319
+ fd.append(name, blob, fileName);
320
+ }
321
+ } else if (type) {
322
+ blob = PayloadSerializer.deserializeBlob(value);
323
+ if (blob) {
324
+ fd.append(name, blob, 'blob');
325
+ }
326
+ } else {
327
+ fd.append(name, value);
328
+ }
329
+ });
330
+ return fd;
331
+ }
332
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts blob data to base64 string.
3
+ *
4
+ * @param blob File or blob object to be translated to string
5
+ * @return Promise resolved to a base64 string data from the file.
6
+ */
7
+ export function blobToDataUrl(blob: Blob): Promise<string> {
8
+ return new Promise((resolve, reject) => {
9
+ const reader = new FileReader();
10
+ reader.onloadend = (): void => {
11
+ resolve(String(reader.result));
12
+ };
13
+ reader.onerror = (): void => {
14
+ reject(new Error('Unable to convert blob to string.'));
15
+ };
16
+ reader.readAsDataURL(blob);
17
+ });
18
+ }
@@ -0,0 +1,40 @@
1
+ const lut: string[] = [];
2
+ for (let i = 0; i < 256; i++) {
3
+ lut[i] = (i < 16 ? '0' : '') + i.toString(16);
4
+ }
5
+
6
+ /**
7
+ * Generate a RFC4122, version 4 ID.
8
+ *
9
+ * @see http://stackoverflow.com/a/21963136/1127848
10
+ * @example "92329D39-6F5C-4520-ABFC-AAB64544E172"
11
+ * @return {string} Generated value
12
+ */
13
+ export default function v4(): string {
14
+ const d0 = (Math.random() * 0xffffffff) | 0;
15
+ const d1 = (Math.random() * 0xffffffff) | 0;
16
+ const d2 = (Math.random() * 0xffffffff) | 0;
17
+ const d3 = (Math.random() * 0xffffffff) | 0;
18
+ return (
19
+ lut[d0 & 0xff] +
20
+ lut[(d0 >> 8) & 0xff] +
21
+ lut[(d0 >> 16) & 0xff] +
22
+ lut[(d0 >> 24) & 0xff] +
23
+ '-' +
24
+ lut[d1 & 0xff] +
25
+ lut[(d1 >> 8) & 0xff] +
26
+ '-' +
27
+ lut[((d1 >> 16) & 0x0f) | 0x40] +
28
+ lut[(d1 >> 24) & 0xff] +
29
+ '-' +
30
+ lut[(d2 & 0x3f) | 0x80] +
31
+ lut[(d2 >> 8) & 0xff] +
32
+ '-' +
33
+ lut[(d2 >> 16) & 0xff] +
34
+ lut[(d2 >> 24) & 0xff] +
35
+ lut[d3 & 0xff] +
36
+ lut[(d3 >> 8) & 0xff] +
37
+ lut[(d3 >> 16) & 0xff] +
38
+ lut[(d3 >> 24) & 0xff]
39
+ );
40
+ }
@@ -0,0 +1,52 @@
1
+ import { DataMockInit, HarTimingInit, HttpRequestInit, HttpResponseRedirectStatusInit } from '@pawel-up/data-mock/types'
2
+
3
+ export interface ArcDataMockInit extends DataMockInit {
4
+ }
5
+
6
+ export interface VariableInit {
7
+ defaultEnv?: boolean;
8
+ randomEnv?: boolean;
9
+ }
10
+
11
+ export declare interface RestApiIndexInit {
12
+ versionSize?: number;
13
+ order?: number;
14
+ }
15
+
16
+ export declare interface HttpResponseArcInit extends HarTimingInit {
17
+ /**
18
+ * When set it does not generate a response payload.
19
+ */
20
+ noBody?: boolean;
21
+ /**
22
+ * The first number of the status group. Other 2 are auto generated
23
+ */
24
+ statusGroup?: number;
25
+ /**
26
+ * Whether to generate timings object
27
+ */
28
+ timings?: boolean;
29
+ /**
30
+ * When set it ignores size information
31
+ */
32
+ noSize?: boolean;
33
+ /**
34
+ * Adds redirects to the request
35
+ */
36
+ redirects?: boolean;
37
+ }
38
+
39
+ export declare interface HttpResponseRedirectInit extends HttpResponseRedirectStatusInit, HarTimingInit {
40
+ /**
41
+ * When set it adds body to the response
42
+ */
43
+ body?: boolean;
44
+ /**
45
+ * The redirection code. Otherwise a random pick is used
46
+ */
47
+ code?: number;
48
+ /**
49
+ * Whether to generate timings object
50
+ */
51
+ timings?: boolean;
52
+ }
@@ -0,0 +1,37 @@
1
+ import { DataMock } from '@pawel-up/data-mock';
2
+ import { Authorization } from './legacy/Authorization.js';
3
+ import { Certificates } from './legacy/Certificates.js';
4
+ import { Cookies } from './legacy/Cookies.js';
5
+ import { HostRules } from './legacy/HostRules.js';
6
+ import { Http } from './legacy/Http.js';
7
+ import { RestApi } from './legacy/RestApi.js';
8
+ import { Urls } from './legacy/Urls.js';
9
+ import { Variables } from './legacy/Variables.js';
10
+ import { ArcDataMockInit } from './LegacyInterfaces.js';
11
+
12
+ export class LegacyMock extends DataMock {
13
+ http: Http;
14
+ variables: Variables;
15
+ cookies: Cookies;
16
+ hostRules: HostRules;
17
+ certificates: Certificates;
18
+ urls: Urls;
19
+ authorization: Authorization;
20
+ restApi: RestApi;
21
+
22
+ /**
23
+ * @param init The library init options.
24
+ */
25
+ constructor(init?: ArcDataMockInit) {
26
+ super(init);
27
+
28
+ this.http = new Http(init);
29
+ this.variables = new Variables(init);
30
+ this.cookies = new Cookies(init);
31
+ this.hostRules = new HostRules(init);
32
+ this.certificates = new Certificates(init);
33
+ this.urls = new Urls(init);
34
+ this.authorization = new Authorization(init);
35
+ this.restApi = new RestApi(init);
36
+ }
37
+ }
@@ -0,0 +1,39 @@
1
+ import { Internet, Types } from '@pawel-up/data-mock';
2
+ import { ArcDataMockInit } from '../LegacyInterfaces.js';
3
+ import { ARCAuthData } from '../../models/legacy/models/AuthData.js';
4
+
5
+ export class Authorization {
6
+ types: Types;
7
+ internet: Internet;
8
+
9
+ constructor(init: ArcDataMockInit={}) {
10
+ this.types = new Types(init.seed);
11
+ this.internet = new Internet(init);
12
+ }
13
+
14
+ /**
15
+ * Generates random Basic authorization object.
16
+ */
17
+ basic(): ARCAuthData {
18
+ const result: ARCAuthData = {
19
+ _id: `basic/${this.types.string()}`,
20
+ username: this.internet.userName(),
21
+ password: this.types.hash(),
22
+ };
23
+ return result;
24
+ }
25
+
26
+ /**
27
+ * Generates basic authorization data
28
+ *
29
+ * @param size Number of items to generate. Default to 25.
30
+ * @return List of datastore entries.
31
+ */
32
+ basicList(size = 25): ARCAuthData[] {
33
+ const result = [];
34
+ for (let i = 0; i < size; i++) {
35
+ result.push(this.basic());
36
+ }
37
+ return result;
38
+ }
39
+ }