@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,87 @@
1
+ import { IClientCertificate, ICertificateIndex, IRequestCertificate } from '../../models/ClientCertificate.js';
2
+ import { ContextReadEvent, ContextListEvent, ContextListOptions, ContextListResult, ContextDeleteEvent, ContextDeleteRecord, ContextUpdateEvent, ContextChangeRecord, ContextStateUpdateEvent, ContextStateDeleteEvent } from '../BaseEvents.js';
3
+ import { ModelEventTypes } from './ModelEventTypes.js';
4
+
5
+ export class ClientCertificateEvents {
6
+ /**
7
+ * Dispatches an event handled by the data store to read the client certificate.
8
+ *
9
+ * @param target A node on which to dispatch the event.
10
+ * @param id The id of the client certificate
11
+ * @param rev The revision of the client certificate. If not set then the latest revision is used.
12
+ * @returns Promise resolved to a client certificate model.
13
+ */
14
+ static async read(target: EventTarget, id: string, rev?: string): Promise<IRequestCertificate | undefined> {
15
+ const e = new ContextReadEvent<IClientCertificate>(ModelEventTypes.ClientCertificate.read, id, rev);
16
+ target.dispatchEvent(e);
17
+ return e.detail.result;
18
+ }
19
+
20
+ /**
21
+ * Dispatches an event to list the client certificates data.
22
+ *
23
+ * @param target A node on which to dispatch the event.
24
+ * @param opts Query options.
25
+ * @returns The list result.
26
+ */
27
+ static async list(target: EventTarget, opts?: ContextListOptions): Promise<ContextListResult<ICertificateIndex> | undefined> {
28
+ const e = new ContextListEvent<ICertificateIndex>(ModelEventTypes.ClientCertificate.list, opts);
29
+ target.dispatchEvent(e);
30
+ return e.detail.result;
31
+ }
32
+
33
+ /**
34
+ * Dispatches an event handled by the data store to delete a client certificate
35
+ *
36
+ * @param target A node on which to dispatch the event.
37
+ * @param id The id of the project to delete.
38
+ * @param rev The revision of the project. If not set then the latest revision is used.
39
+ * @returns Promise resolved to a new revision after delete.
40
+ */
41
+ static async delete(target: EventTarget, id: string, rev?: string): Promise<ContextDeleteRecord | undefined> {
42
+ const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete, id, undefined, rev);
43
+ target.dispatchEvent(e);
44
+ return e.detail.result;
45
+ }
46
+
47
+ /**
48
+ * Dispatches an event handled by the data store to insert a new client certificate.
49
+ *
50
+ * @param target A node on which to dispatch the event.
51
+ * @param item The certificate object.
52
+ * @returns Promise resolved to the change record
53
+ */
54
+ static async insert(target: EventTarget, item: IClientCertificate): Promise<ContextChangeRecord<ICertificateIndex> | undefined> {
55
+ const e = new ContextUpdateEvent<IClientCertificate>(ModelEventTypes.ClientCertificate.insert, { item, });
56
+ target.dispatchEvent(e);
57
+ return e.detail.result;
58
+ }
59
+
60
+ static get State(): typeof StateEvents {
61
+ return StateEvents;
62
+ }
63
+ }
64
+
65
+ class StateEvents {
66
+ /**
67
+ * Dispatches an event after a client certificate was updated
68
+ *
69
+ * @param target A node on which to dispatch the event.
70
+ * @param record Change record
71
+ */
72
+ static update(target: EventTarget, record: ContextChangeRecord<ICertificateIndex>): void {
73
+ const e = new ContextStateUpdateEvent<ICertificateIndex>(ModelEventTypes.ClientCertificate.State.update, record);
74
+ target.dispatchEvent(e);
75
+ }
76
+
77
+ /**
78
+ * Dispatches an event after a client certificate was deleted
79
+ *
80
+ * @param target A node on which to dispatch the event.
81
+ * @param record The context store delete record
82
+ */
83
+ static delete(target: EventTarget, record: ContextDeleteRecord): void {
84
+ const e = new ContextStateDeleteEvent(ModelEventTypes.ClientCertificate.State.delete, record);
85
+ target.dispatchEvent(e);
86
+ }
87
+ }
@@ -0,0 +1,47 @@
1
+ export const ModelEventTypes = {
2
+ ClientCertificate: Object.freeze({
3
+ read: 'storeclientcertificateread',
4
+ list: 'storeclientcertificatelist',
5
+ delete: 'storeclientcertificatedelete',
6
+ update: 'storeclientcertificateupdate',
7
+ insert: 'storeclientcertificateinsert',
8
+ State: Object.freeze({
9
+ update: 'storestateclientcertificateupdate',
10
+ delete: 'storestateclientcertificatedelete',
11
+ }),
12
+ }),
13
+ Project: Object.freeze({
14
+ create: 'storeprojectcreate',
15
+ read: 'storeprojectread',
16
+ update: 'storeprojectupdate',
17
+ delete: 'storeprojectdelete',
18
+ /**
19
+ * Moves objects inside a project between position and/or folders.
20
+ */
21
+ move: 'storeprojectmove',
22
+ /**
23
+ * Makes a copy of the project and stores it as new.
24
+ */
25
+ clone: 'storeprojectclone',
26
+ listAll: 'storeprojectlistall', // without pagination
27
+ Folder: Object.freeze({
28
+ create: 'storeprojectfoldercreate',
29
+ delete: 'storeprojectfolderdelete',
30
+ update: 'storeprojectfolderupdate',
31
+ }),
32
+ Request: Object.freeze({
33
+ create: 'storeprojectrequestcreate',
34
+ delete: 'storeprojectrequestdelete',
35
+ update: 'storeprojectrequestupdate',
36
+ }),
37
+ Environment: Object.freeze({
38
+ create: 'storeprojectenvironmentcreate',
39
+ delete: 'storeprojectenvironmentdelete',
40
+ update: 'storeprojectenvironmentupdate',
41
+ }),
42
+ State: Object.freeze({
43
+ update: 'storeprojectstateupdate',
44
+ delete: 'storeprojectstatedelete',
45
+ })
46
+ }),
47
+ }
@@ -0,0 +1,7 @@
1
+ import { ClientCertificateEvents } from './ClientCertificateEvents.js';
2
+ import { ProjectEvents } from './ProjectEvents.js';
3
+
4
+ export const ModelEvents = Object.freeze({
5
+ Project: ProjectEvents,
6
+ ClientCertificate: ClientCertificateEvents,
7
+ });
@@ -0,0 +1,331 @@
1
+ import { IHttpProject, IProjectInitOptions, IProjectMoveOptions, IHttpProjectIndex, IFolderCreateOptions, IRequestAddOptions } from "../../models/HttpProject.js";
2
+ import { IProjectFolder } from "../../models/ProjectFolder.js";
3
+ import { IProjectRequest } from "../../models/ProjectRequest.js";
4
+ import { IEnvironment } from "../../models/Environment.js";
5
+ import { ContextChangeRecord, ContextEvent, ContextReadEvent, ContextUpdateEvent, ContextDeleteRecord, ContextDeleteEvent, ContextEventDetailWithResult } from "../BaseEvents.js";
6
+ import { ModelEventTypes } from './ModelEventTypes.js';
7
+ import CustomEvent from '../CustomEvent.js';
8
+
9
+ export interface ProjectMoveEventDetail {
10
+ type: 'request' | 'folder';
11
+ key: string;
12
+ opts?: IProjectMoveOptions;
13
+ }
14
+
15
+ export interface ProjectCloneEventDetail {
16
+ /**
17
+ * The id of the project to clone in the data store.
18
+ */
19
+ id: string;
20
+ }
21
+
22
+ /**
23
+ * A list of options to initialize a folder in a project.
24
+ */
25
+ export interface IFolderInitOptions extends IFolderCreateOptions {
26
+ /**
27
+ * The store id of the project.
28
+ */
29
+ id: string;
30
+ /**
31
+ * Optional name of the new folder.
32
+ */
33
+ name?: string;
34
+ }
35
+
36
+ /**
37
+ * A list of options to initialize a request in a project.
38
+ */
39
+ export interface IRequestInitOptions extends IRequestAddOptions {
40
+ /**
41
+ * The store id of the project.
42
+ */
43
+ id: string;
44
+ /**
45
+ * The URL of the request.
46
+ */
47
+ url: string;
48
+ }
49
+
50
+ export interface IEnvironmentInitOptions {
51
+ /**
52
+ * The store id of the project.
53
+ */
54
+ id: string;
55
+ /**
56
+ * The name of the environment to create.
57
+ */
58
+ name: string;
59
+ /**
60
+ * The optional key of the parent folder.
61
+ */
62
+ key?: string;
63
+ }
64
+
65
+ class ProjectFolderEvents {
66
+ /**
67
+ * Creates a folder in a project.
68
+ *
69
+ * @param target The target on which to dispatch the event
70
+ * @param id The store id of the project
71
+ * @param name Optionally, name of the folder to create.
72
+ * @param opts Optional options to create a folder.
73
+ * @returns The change record of the created folder. Note, the client should either refresh the project from the store or append the change record to the instance of the project.
74
+ */
75
+ static async create(target: EventTarget, id: string, name?: string, opts: IFolderCreateOptions = {}): Promise<ContextChangeRecord<IProjectFolder> | undefined> {
76
+ const init: IFolderInitOptions = { ...opts, id, name, };
77
+ const e = new ContextEvent<IFolderInitOptions, ContextChangeRecord<IProjectFolder>>(ModelEventTypes.Project.Folder.create, init);
78
+ target.dispatchEvent(e);
79
+ return e.detail.result;
80
+ }
81
+
82
+ /**
83
+ * Deletes a folder from a project
84
+ *
85
+ * @param target The target on which to dispatch the event
86
+ * @param id The data store id of the project
87
+ * @param key The key of the folder to delete.
88
+ */
89
+ static async delete(target: EventTarget, id: string, key: string): Promise<ContextDeleteRecord | undefined> {
90
+ const e = new ContextDeleteEvent(ModelEventTypes.Project.Folder.delete, key, id);
91
+ target.dispatchEvent(e);
92
+ return e.detail.result;
93
+ }
94
+
95
+ /**
96
+ * Updates the entire folder schema in a project.
97
+ *
98
+ * @param target The target on which to dispatch the event
99
+ * @param id The data store id of the project
100
+ * @param folder The folder to replace the schema for.
101
+ * @returns The change record of the updated folder.
102
+ */
103
+ static async update(target: EventTarget, id: string, folder: IProjectFolder): Promise<ContextChangeRecord<IProjectFolder> | undefined> {
104
+ const e = new ContextUpdateEvent(ModelEventTypes.Project.Folder.update, { item: folder, parent: id });
105
+ target.dispatchEvent(e);
106
+ return e.detail.result;
107
+ }
108
+ }
109
+
110
+ class ProjectRequestEvents {
111
+ /**
112
+ * Creates a request in a project.
113
+ *
114
+ * @param target The target on which to dispatch the event
115
+ * @param id The store id of the project
116
+ * @param url The URL of the request.
117
+ * @param opts Optional options to create a request.
118
+ * @returns The change record of the created request. Note, the client should either refresh the project from the store or append the change record to the instance of the project.
119
+ */
120
+ static async create(target: EventTarget, id: string, url: string, opts: IRequestAddOptions = {}): Promise<ContextChangeRecord<IProjectRequest> | undefined> {
121
+ const init: IRequestInitOptions = { ...opts, id, url, };
122
+ const e = new ContextEvent<IRequestInitOptions, ContextChangeRecord<IProjectRequest>>(ModelEventTypes.Project.Request.create, init);
123
+ target.dispatchEvent(e);
124
+ return e.detail.result;
125
+ }
126
+
127
+ /**
128
+ * Deletes a request from a project
129
+ *
130
+ * @param target The target on which to dispatch the event
131
+ * @param id The data store id of the project
132
+ * @param key The key of the request to delete.
133
+ */
134
+ static async delete(target: EventTarget, id: string, key: string): Promise<ContextDeleteRecord | undefined> {
135
+ const e = new ContextDeleteEvent(ModelEventTypes.Project.Request.delete, key, id);
136
+ target.dispatchEvent(e);
137
+ return e.detail.result;
138
+ }
139
+
140
+ /**
141
+ * Updates the entire request schema in a project.
142
+ *
143
+ * @param target The target on which to dispatch the event
144
+ * @param id The data store id of the project
145
+ * @param request The request to replace the schema for.
146
+ * @returns The change record of the updated request.
147
+ */
148
+ static async update(target: EventTarget, id: string, request: IProjectRequest): Promise<ContextChangeRecord<IProjectRequest> | undefined> {
149
+ const e = new ContextUpdateEvent(ModelEventTypes.Project.Request.update, { item: request, parent: id });
150
+ target.dispatchEvent(e);
151
+ return e.detail.result;
152
+ }
153
+ }
154
+
155
+ class ProjectEnvironmentEvents {
156
+ /**
157
+ * Creates an environment in a project.
158
+ *
159
+ * @param target The target on which to dispatch the event
160
+ * @param id The store id of the project
161
+ * @param name The name of the environment.
162
+ * @param key The optional key of the parent folder.
163
+ * @returns The change record of the created environment. Note, the client should either refresh the project from the store or append the change record to the instance of the project.
164
+ */
165
+ static async create(target: EventTarget, id: string, name: string, key?: string): Promise<ContextChangeRecord<IEnvironment> | undefined> {
166
+ const init: IEnvironmentInitOptions = { id, name, key };
167
+ const e = new ContextEvent<IEnvironmentInitOptions, ContextChangeRecord<IEnvironment>>(ModelEventTypes.Project.Environment.create, init);
168
+ target.dispatchEvent(e);
169
+ return e.detail.result;
170
+ }
171
+
172
+ /**
173
+ * Deletes an environment from a project
174
+ *
175
+ * @param target The target on which to dispatch the event
176
+ * @param id The data store id of the project
177
+ * @param key The key of the environment to delete.
178
+ */
179
+ static async delete(target: EventTarget, id: string, key: string): Promise<ContextDeleteRecord | undefined> {
180
+ const e = new ContextDeleteEvent(ModelEventTypes.Project.Environment.delete, key, id);
181
+ target.dispatchEvent(e);
182
+ return e.detail.result;
183
+ }
184
+
185
+ /**
186
+ * Updates the entire environment schema in a project.
187
+ *
188
+ * @param target The target on which to dispatch the event
189
+ * @param id The data store id of the project
190
+ * @param environment The environment to replace the schema for.
191
+ * @returns The change record of the updated environment.
192
+ */
193
+ static async update(target: EventTarget, id: string, environment: IEnvironment): Promise<ContextChangeRecord<IEnvironment> | undefined> {
194
+ const e = new ContextUpdateEvent(ModelEventTypes.Project.Environment.update, { item: environment, parent: id });
195
+ target.dispatchEvent(e);
196
+ return e.detail.result;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * ARC's HTTP project events.
202
+ *
203
+ * Note, `id`s refers to datastore ids but `key`s are internal identifiers inside the project.
204
+ * Whenever id is used it refers to the store's ids. When `key` is used it is the id of the project or any of its components.
205
+ */
206
+ export class ProjectEvents {
207
+ /**
208
+ * Creates a new project in the data store.
209
+ *
210
+ * @param target The target on which to dispatch the event
211
+ * @param name The name of the project to create
212
+ * @returns The change record of the created project.
213
+ */
214
+ static async create(target: EventTarget, name: string): Promise<ContextChangeRecord<IHttpProject> | undefined> {
215
+ const e = new ContextEvent<IProjectInitOptions, ContextChangeRecord<IHttpProject>>(ModelEventTypes.Project.create, { name });
216
+ target.dispatchEvent(e);
217
+ return e.detail.result;
218
+ }
219
+
220
+ /**
221
+ * Reads a project from the data store.
222
+ *
223
+ * @param target The target on which to dispatch the event
224
+ * @param id The data store id of the project to read.
225
+ * @param rev Optional revision version, when supported.
226
+ */
227
+ static async read(target: EventTarget, id: string, rev?: string): Promise<IHttpProject | undefined> {
228
+ const e = new ContextReadEvent<IHttpProject>(ModelEventTypes.Project.read, id, rev);
229
+ target.dispatchEvent(e);
230
+ return e.detail.result;
231
+ }
232
+
233
+ /**
234
+ * Updates the entire object in the store.
235
+ *
236
+ * @param target The target on which to dispatch the event
237
+ * @param project The project to replace the value for.
238
+ * @returns The change record of the updated project.
239
+ */
240
+ static async update(target: EventTarget, project: IHttpProject): Promise<ContextChangeRecord<IHttpProject> | undefined> {
241
+ const e = new ContextUpdateEvent(ModelEventTypes.Project.update, { item: project });
242
+ target.dispatchEvent(e);
243
+ return e.detail.result;
244
+ }
245
+
246
+ /**
247
+ * Deletes a project from the data store.
248
+ *
249
+ * @param target The target on which to dispatch the event
250
+ * @param id The data store id of the project to delete.
251
+ */
252
+ static async delete(target: EventTarget, id: string): Promise<ContextDeleteRecord | undefined> {
253
+ const e = new ContextDeleteEvent(ModelEventTypes.Project.delete, id);
254
+ target.dispatchEvent(e);
255
+ return e.detail.result;
256
+ }
257
+
258
+ /**
259
+ * Moves a request or a folder inside the project.
260
+ *
261
+ * @param target The target on which to dispatch the event
262
+ * @param type The type of the object to move within the project.
263
+ * @param key The `key` of the request of the folder
264
+ * @param opts The move options. When omitted then it moves the object to the project root at the last position.
265
+ * @returns The change record of the updated project.
266
+ */
267
+ static async move(target: EventTarget, type: 'request' | 'folder', key: string, opts?: IProjectMoveOptions): Promise<ContextChangeRecord<IHttpProject> | undefined> {
268
+ const e = new ContextEvent<ProjectMoveEventDetail, ContextChangeRecord<IHttpProject>>(ModelEventTypes.Project.move, {
269
+ key,
270
+ type,
271
+ opts,
272
+ });
273
+ target.dispatchEvent(e);
274
+ return e.detail.result;
275
+ }
276
+
277
+ /**
278
+ * Clones a project that is stored in the data store.
279
+ *
280
+ * @param target The target on which to dispatch the event
281
+ * @param id The data store id of the project to clone.
282
+ * @returns The cloned project (the copy).
283
+ */
284
+ static async clone(target: EventTarget, id: string): Promise<ContextChangeRecord<IHttpProject> | undefined> {
285
+ const e = new ContextEvent<ProjectCloneEventDetail, ContextChangeRecord<IHttpProject>>(ModelEventTypes.Project.clone, {
286
+ id,
287
+ });
288
+ target.dispatchEvent(e);
289
+ return e.detail.result;
290
+ }
291
+
292
+ /**
293
+ * Lists all projects in the data store.
294
+ * This does not return the whole project record. Instead it only returns the index object of the project.
295
+ *
296
+ * @param target The target on which to dispatch the event
297
+ * @returns The list of project index objects.
298
+ */
299
+ static async listAll(target: EventTarget): Promise<IHttpProjectIndex[] | undefined> {
300
+ const detail: ContextEventDetailWithResult<IHttpProjectIndex[]> = {};
301
+ const e = new CustomEvent(ModelEventTypes.Project.listAll, {
302
+ bubbles: true,
303
+ composed: true,
304
+ cancelable: true,
305
+ detail,
306
+ });
307
+ target.dispatchEvent(e);
308
+ return e.detail.result;
309
+ }
310
+
311
+ /**
312
+ * Events related to a folder manipulation in a project.
313
+ */
314
+ static get Folder(): typeof ProjectFolderEvents {
315
+ return ProjectFolderEvents;
316
+ }
317
+
318
+ /**
319
+ * Events related to a request manipulation in a project.
320
+ */
321
+ static get Request(): typeof ProjectRequestEvents {
322
+ return ProjectRequestEvents;
323
+ }
324
+
325
+ /**
326
+ * Events related to an environment manipulation in a project.
327
+ */
328
+ static get Environment(): typeof ProjectEnvironmentEvents {
329
+ return ProjectEnvironmentEvents;
330
+ }
331
+ };
@@ -0,0 +1,5 @@
1
+ export const ProcessEventTypes = Object.freeze({
2
+ loadingStart: 'processloadingstart',
3
+ loadingStop: 'processloadingstop',
4
+ loadingError: 'processloadingerror',
5
+ });
@@ -0,0 +1,76 @@
1
+ import { ProcessEventTypes } from './ProcessEventTypes.js';
2
+
3
+ export interface IProcessStartDetail {
4
+ pid: string;
5
+ message: string;
6
+ }
7
+
8
+ export interface IProcessStopDetail {
9
+ pid: string;
10
+ }
11
+
12
+ export interface IProcessErrorDetail {
13
+ pid: string;
14
+ message: string;
15
+ error?: Error
16
+ }
17
+
18
+ export class ProcessEvents {
19
+ /**
20
+ * An event to be dispatched when the application is stating a long running process
21
+ * in the background. The side effect of the event is the UI showing a process
22
+ * indicator.
23
+ *
24
+ * @param target A node on which to dispatch the event.
25
+ * @param pid The id of the process. The same id has to be passed to the stop event.
26
+ * @param message Optional message rendered in the UI.
27
+ */
28
+ static loadingStart(target: EventTarget, pid: string, message: string): void {
29
+ const detail: IProcessStartDetail = { pid, message };
30
+ const e = new CustomEvent(ProcessEventTypes.loadingStart, {
31
+ cancelable: true,
32
+ composed: true,
33
+ bubbles: true,
34
+ detail,
35
+ });
36
+ target.dispatchEvent(e);
37
+ }
38
+
39
+ /**
40
+ * An event to be dispatched when the application has finished a long running process
41
+ * in the background.
42
+ *
43
+ * @param target A node on which to dispatch the event.
44
+ * @param pid The id of the process. The same id has to be passed to the stop event.
45
+ */
46
+ static loadingStop(target: EventTarget, pid: string): void {
47
+ const detail: IProcessStopDetail = { pid };
48
+ const e = new CustomEvent(ProcessEventTypes.loadingStop, {
49
+ cancelable: true,
50
+ composed: true,
51
+ bubbles: true,
52
+ detail,
53
+ });
54
+ target.dispatchEvent(e);
55
+ }
56
+
57
+ /**
58
+ * An event to be dispatched when the application has finished a long running process
59
+ * in the background with an error.
60
+ *
61
+ * @param target A node on which to dispatch the event.
62
+ * @param pid The id of the process used to start it.
63
+ * @param message The message to be rendered to the user.
64
+ * @param error The error object caused the event. Optional.
65
+ */
66
+ static loadingError(target: EventTarget, pid: string, message: string, error?: Error): void {
67
+ const detail: IProcessErrorDetail = { pid, message, error };
68
+ const e = new CustomEvent(ProcessEventTypes.loadingError, {
69
+ cancelable: true,
70
+ composed: true,
71
+ bubbles: true,
72
+ detail,
73
+ });
74
+ target.dispatchEvent(e);
75
+ }
76
+ }
@@ -0,0 +1,22 @@
1
+ # Events
2
+
3
+ This package contains a definition of events used by the ARC ecosystem to communicate with context providers.
4
+
5
+ ## Context provider
6
+
7
+ A context provider is any service that is listening for relevant events and responds to them by taking some action.
8
+
9
+ For example a Store Context Provider is a provider that listens to events related to the data models and performs CRUD operations on the data store. The result of the operation is passed to the `result` object of the event. The event is an instance of the CustomEvent class.
10
+
11
+ ## Communication architecture
12
+
13
+ A module or an application wants to read the context value from a context provider. The module dispatches a CustomEvent on the application's EventTarget with the corresponding `type` handled by the context provider.
14
+
15
+ The provider handles the event, cancels it (when applicable, prevents duplication), and calls the corresponding asynchronous logic. The result of the operation is always a Promise. The promise is resolved when the operation finish
16
+
17
+ The promise is set on the `detail` object if the `CustomEvent` as the `result` property.
18
+
19
+ This has the following implications:
20
+
21
+ - all events are processed asynchronously
22
+ - all events must extend `CustomEvent` class, unless they have no side effects (no result, no data to pass to the provider)
@@ -0,0 +1,3 @@
1
+ export const ReportingEventTypes = Object.freeze({
2
+ error: 'reporterror',
3
+ });
@@ -0,0 +1,28 @@
1
+ import { ReportingEventTypes } from './ReportingEventTypes.js';
2
+
3
+ export interface IReportingErrorDetail {
4
+ description: string;
5
+ error?: Error;
6
+ component?: string;
7
+ }
8
+
9
+ export class ReportingEvents {
10
+ /**
11
+ * Dispatches the general error event for UI logging purposes.
12
+ *
13
+ * @param target A node on which to dispatch the event
14
+ * @param description The error description
15
+ * @param error Optional original error object that has caused this event
16
+ * @param component Optional component name.
17
+ */
18
+ static error(target: EventTarget, description: string, error?: Error, component?: string): void {
19
+ const detail: IReportingErrorDetail = { error, description, component };
20
+ const e = new CustomEvent(ReportingEventTypes.error, {
21
+ bubbles: true,
22
+ composed: true,
23
+ cancelable: true,
24
+ detail,
25
+ });
26
+ target.dispatchEvent(e);
27
+ }
28
+ }
@@ -0,0 +1,10 @@
1
+ export const TelemetryEventTypes = Object.freeze({
2
+ view: 'telemetryscreenview',
3
+ event: 'telemetryevent',
4
+ exception: 'telemetryexception',
5
+ social: 'telemetrysocial',
6
+ timing: 'telemetrytiming',
7
+ State: Object.freeze({
8
+ set: 'telemetrystateset',
9
+ }),
10
+ });