@api-client/core 0.5.19 → 0.5.22

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 (104) hide show
  1. package/build/browser.d.ts +9 -2
  2. package/build/browser.js +12 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +6 -2
  5. package/build/index.js +9 -0
  6. package/build/index.js.map +1 -1
  7. package/build/src/authorization/AuthorizationError.d.ts +23 -0
  8. package/build/src/authorization/AuthorizationError.js +33 -0
  9. package/build/src/authorization/AuthorizationError.js.map +1 -0
  10. package/build/src/authorization/CustomParameters.d.ts +24 -0
  11. package/build/src/authorization/CustomParameters.js +59 -0
  12. package/build/src/authorization/CustomParameters.js.map +1 -0
  13. package/build/src/authorization/OAuth2Authorization.d.ts +332 -0
  14. package/build/src/authorization/OAuth2Authorization.js +965 -0
  15. package/build/src/authorization/OAuth2Authorization.js.map +1 -0
  16. package/build/src/authorization/OidcAuthorization.d.ts +34 -0
  17. package/build/src/authorization/OidcAuthorization.js +139 -0
  18. package/build/src/authorization/OidcAuthorization.js.map +1 -0
  19. package/build/src/authorization/Utils.d.ts +51 -0
  20. package/build/src/authorization/Utils.js +122 -0
  21. package/build/src/authorization/Utils.js.map +1 -0
  22. package/build/src/authorization/lib/IframeAuthorization.d.ts +53 -0
  23. package/build/src/authorization/lib/IframeAuthorization.js +116 -0
  24. package/build/src/authorization/lib/IframeAuthorization.js.map +1 -0
  25. package/build/src/authorization/lib/KnownGrants.d.ts +6 -0
  26. package/build/src/authorization/lib/KnownGrants.js +7 -0
  27. package/build/src/authorization/lib/KnownGrants.js.map +1 -0
  28. package/build/src/authorization/lib/PopupAuthorization.d.ts +41 -0
  29. package/build/src/authorization/lib/PopupAuthorization.js +73 -0
  30. package/build/src/authorization/lib/PopupAuthorization.js.map +1 -0
  31. package/build/src/authorization/lib/Tokens.d.ts +55 -0
  32. package/build/src/authorization/lib/Tokens.js +117 -0
  33. package/build/src/authorization/lib/Tokens.js.map +1 -0
  34. package/build/src/authorization/types.d.ts +174 -0
  35. package/build/src/authorization/types.js +2 -0
  36. package/build/src/authorization/types.js.map +1 -0
  37. package/build/src/events/BaseEvents.d.ts +1 -1
  38. package/build/src/events/BaseEvents.js.map +1 -1
  39. package/build/src/events/EventTypes.d.ts +0 -28
  40. package/build/src/events/Events.d.ts +0 -1
  41. package/build/src/events/models/ClientCertificateEvents.d.ts +6 -8
  42. package/build/src/events/models/ClientCertificateEvents.js +4 -6
  43. package/build/src/events/models/ClientCertificateEvents.js.map +1 -1
  44. package/build/src/events/models/ModelEventTypes.d.ts +0 -34
  45. package/build/src/events/models/ModelEventTypes.js +0 -34
  46. package/build/src/events/models/ModelEventTypes.js.map +1 -1
  47. package/build/src/events/models/ModelEvents.d.ts +0 -2
  48. package/build/src/events/models/ModelEvents.js +0 -2
  49. package/build/src/events/models/ModelEvents.js.map +1 -1
  50. package/build/src/lib/Buffer.d.ts +21 -0
  51. package/build/src/lib/Buffer.js +43 -0
  52. package/build/src/lib/Buffer.js.map +1 -0
  53. package/build/src/models/Authorization.d.ts +3 -5
  54. package/build/src/models/ClientCertificate.d.ts +130 -25
  55. package/build/src/models/ClientCertificate.js +150 -1
  56. package/build/src/models/ClientCertificate.js.map +1 -1
  57. package/build/src/models/Request.d.ts +3 -3
  58. package/build/src/models/Request.js +3 -2
  59. package/build/src/models/Request.js.map +1 -1
  60. package/build/src/models/RequestAuthorization.js +4 -0
  61. package/build/src/models/RequestAuthorization.js.map +1 -1
  62. package/build/src/runtime/http-engine/CoreEngine.js +4 -1
  63. package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
  64. package/build/src/runtime/http-engine/HttpEngine.d.ts +4 -4
  65. package/build/src/runtime/http-engine/HttpEngine.js +38 -29
  66. package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
  67. package/build/src/runtime/modules/ModulesRegistry.d.ts +2 -2
  68. package/build/src/runtime/modules/RequestAuthorization.js +3 -7
  69. package/build/src/runtime/modules/RequestAuthorization.js.map +1 -1
  70. package/build/src/runtime/node/ProjectRequestRunner.js +1 -1
  71. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  72. package/build/src/runtime/node/RequestFactory.d.ts +2 -2
  73. package/build/src/runtime/node/RequestFactory.js.map +1 -1
  74. package/oauth-popup.html +29 -0
  75. package/package.json +3 -1
  76. package/src/authorization/AuthorizationError.ts +25 -0
  77. package/src/authorization/CustomParameters.ts +61 -0
  78. package/src/authorization/OAuth2Authorization.ts +1027 -0
  79. package/src/authorization/OidcAuthorization.ts +143 -0
  80. package/src/authorization/Utils.ts +126 -0
  81. package/src/authorization/lib/IframeAuthorization.ts +128 -0
  82. package/src/authorization/lib/KnownGrants.ts +6 -0
  83. package/src/authorization/lib/PopupAuthorization.ts +80 -0
  84. package/src/authorization/lib/Tokens.ts +124 -0
  85. package/src/authorization/types.ts +176 -0
  86. package/src/events/BaseEvents.ts +1 -1
  87. package/src/events/models/ClientCertificateEvents.ts +11 -13
  88. package/src/events/models/ModelEventTypes.ts +0 -34
  89. package/src/events/models/ModelEvents.ts +0 -2
  90. package/src/lib/Buffer.ts +48 -0
  91. package/src/models/Authorization.ts +4 -5
  92. package/src/models/ClientCertificate.ts +224 -25
  93. package/src/models/Request.ts +5 -5
  94. package/src/models/RequestAuthorization.ts +5 -1
  95. package/src/runtime/http-engine/CoreEngine.ts +4 -1
  96. package/src/runtime/http-engine/HttpEngine.ts +39 -33
  97. package/src/runtime/modules/ModulesRegistry.ts +2 -2
  98. package/src/runtime/modules/RequestAuthorization.ts +3 -7
  99. package/src/runtime/node/ProjectRequestRunner.ts +1 -1
  100. package/src/runtime/node/RequestFactory.ts +2 -2
  101. package/build/src/events/models/ProjectEvents.d.ts +0 -221
  102. package/build/src/events/models/ProjectEvents.js +0 -253
  103. package/build/src/events/models/ProjectEvents.js.map +0 -1
  104. package/src/events/models/ProjectEvents.ts +0 -331
@@ -0,0 +1,176 @@
1
+ export interface OauthProcessingOptions {
2
+ /**
3
+ * The number of milliseconds of an interval to check the popup state.
4
+ * Default to 250 ms.
5
+ */
6
+ popupPullTimeout?: number;
7
+ /**
8
+ * The event target on which to listen to the redirect page `message` event.
9
+ * This event should contain a list of authorization parameters returned by the authorization server.
10
+ *
11
+ * The library contains `oauth-popup.html` page that reads the data from the URL and posts it back to the opener.
12
+ * However, you can create `tokenInfoTranslation` to map returned by the popup parameters to the onces used by the library.
13
+ */
14
+ messageTarget?: EventTarget;
15
+ /**
16
+ * A number of milliseconds after which the iframe triggers a timeout if the response is not present.
17
+ * Defaults to `1020`.
18
+ */
19
+ iframeTimeout?: number;
20
+ /**
21
+ * When set it uses this value to prefix the call to the
22
+ * OAuth 2 token endpoint. This is to support use cases when
23
+ * the requests should be proxied through a server to avoid CORS problems.
24
+ */
25
+ tokenProxy?: string;
26
+ /**
27
+ * When set it encodes the token URI value before adding it to the
28
+ * `tokenProxy`. This is to be used when the proxy takes the target
29
+ * URL as a query parameter.
30
+ */
31
+ tokenProxyEncode?: boolean;
32
+ }
33
+
34
+ export interface IOpenIdProviderMetadata {
35
+ /**
36
+ * URL using the https scheme with no query or fragment component that the OP asserts as its Issuer Identifier. If Issuer discovery is supported (see Section 2), this value MUST be identical to the issuer value returned by WebFinger. This also MUST be identical to the iss Claim value in ID Tokens issued from this Issuer.
37
+ */
38
+ issuer: string;
39
+ /**
40
+ * URL of the OP's OAuth 2.0 Authorization Endpoint [OpenID.Core].
41
+ */
42
+ authorization_endpoint: string;
43
+ /**
44
+ * URL of the OP's OAuth 2.0 Token Endpoint [OpenID.Core]. This is REQUIRED unless only the Implicit Flow is used.
45
+ */
46
+ token_endpoint?: string;
47
+ /**
48
+ * URL of the OP's UserInfo Endpoint [OpenID.Core]. This URL MUST use the https scheme and MAY contain port, path, and query parameter components.
49
+ */
50
+ userinfo_endpoint?: string;
51
+ /**
52
+ * URL of the OP's JSON Web Key Set [JWK] document. This contains the signing key(s) the RP uses to validate signatures from the OP. The JWK Set MAY also contain the Server's encryption key(s), which are used by RPs to encrypt requests to the Server. When both signing and encryption keys are made available, a use (Key Use) parameter value is REQUIRED for all keys in the referenced JWK Set to indicate each key's intended usage. Although some algorithms allow the same key to be used for both signatures and encryption, doing so is NOT RECOMMENDED, as it is less secure. The JWK x5c parameter MAY be used to provide X.509 representations of keys provided. When used, the bare key values MUST still be present and MUST match those in the certificate.
53
+ */
54
+ jwks_uri: string;
55
+ /**
56
+ * URL of the OP's Dynamic Client Registration Endpoint.
57
+ */
58
+ registration_endpoint?: string;
59
+ /**
60
+ * JSON array containing a list of the OAuth 2.0 [RFC6749] scope values that this server supports. The server MUST support the openid scope value. Servers MAY choose not to advertise some supported scope values even when this parameter is used, although those defined in [OpenID.Core] SHOULD be listed, if supported.
61
+ */
62
+ scopes_supported?: string[];
63
+ /**
64
+ * JSON array containing a list of the OAuth 2.0 response_type values that this OP supports. Dynamic OpenID Providers MUST support the code, id_token, and the token id_token Response Type values.
65
+ */
66
+ response_types_supported: string[];
67
+ /**
68
+ * JSON array containing a list of the OAuth 2.0 response_mode values that this OP supports, as specified in OAuth 2.0 Multiple Response Type Encoding Practices [OAuth.Responses]. If omitted, the default for Dynamic OpenID Providers is ["query", "fragment"].
69
+ */
70
+ response_modes_supported?: string[];
71
+ /**
72
+ * JSON array containing a list of the OAuth 2.0 Grant Type values that this OP supports. Dynamic OpenID Providers MUST support the authorization_code and implicit Grant Type values and MAY support other Grant Types. If omitted, the default value is ["authorization_code", "implicit"].
73
+ */
74
+ grant_types_supported?: string[];
75
+ /**
76
+ * JSON array containing a list of the Authentication Context Class References that this OP supports.
77
+ */
78
+ acr_values_supported?: string[];
79
+ /**
80
+ * JSON array containing a list of the Subject Identifier types that this OP supports. Valid types include pairwise and public.
81
+ */
82
+ subject_types_supported: string[];
83
+ /**
84
+ * JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT]. The algorithm RS256 MUST be included. The value none MAY be supported, but MUST NOT be used unless the Response Type used returns no ID Token from the Authorization Endpoint (such as when using the Authorization Code Flow).
85
+ */
86
+ id_token_signing_alg_values_supported: string[];
87
+ /**
88
+ * JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT].
89
+ */
90
+ id_token_encryption_alg_values_supported?: string[];
91
+ /**
92
+ * JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT].
93
+ */
94
+ id_token_encryption_enc_values_supported?: string[];
95
+ /**
96
+ * JSON array containing a list of the JWS [JWS] signing algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT]. The value none MAY be included.
97
+ */
98
+ userinfo_signing_alg_values_supported?: string[];
99
+ /**
100
+ * JSON array containing a list of the JWE [JWE] encryption algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT].
101
+ */
102
+ userinfo_encryption_alg_values_supported?: string[];
103
+ /**
104
+ * JSON array containing a list of the JWE encryption algorithms (enc values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT].
105
+ */
106
+ userinfo_encryption_enc_values_supported?: string[];
107
+ /**
108
+ * JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for Request Objects, which are described in Section 6.1 of OpenID Connect Core 1.0 [OpenID.Core]. These algorithms are used both when the Request Object is passed by value (using the request parameter) and when it is passed by reference (using the request_uri parameter). Servers SHOULD support none and RS256.
109
+ */
110
+ request_object_signing_alg_values_supported?: string[];
111
+ /**
112
+ * JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for Request Objects. These algorithms are used both when the Request Object is passed by value and when it is passed by reference.
113
+ */
114
+ request_object_encryption_alg_values_supported?: string[];
115
+ /**
116
+ * JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for Request Objects. These algorithms are used both when the Request Object is passed by value and when it is passed by reference.
117
+ */
118
+ request_object_encryption_enc_values_supported?: string[];
119
+ /**
120
+ * JSON array containing a list of Client Authentication methods supported by this Token Endpoint. The options are client_secret_post, client_secret_basic, client_secret_jwt, and private_key_jwt, as described in Section 9 of OpenID Connect Core 1.0 [OpenID.Core]. Other authentication methods MAY be defined by extensions. If omitted, the default is client_secret_basic -- the HTTP Basic Authentication Scheme specified in Section 2.3.1 of OAuth 2.0 [RFC6749].
121
+ */
122
+ token_endpoint_auth_methods_supported?: string[];
123
+ /**
124
+ * JSON array containing a list of the JWS signing algorithms (alg values) supported by the Token Endpoint for the signature on the JWT [JWT] used to authenticate the Client at the Token Endpoint for the private_key_jwt and client_secret_jwt authentication methods. Servers SHOULD support RS256. The value none MUST NOT be used.
125
+ */
126
+ token_endpoint_auth_signing_alg_values_supported?: string[];
127
+ /**
128
+ * JSON array containing a list of the display parameter values that the OpenID Provider supports. These values are described in Section 3.1.2.1 of OpenID Connect Core 1.0 [OpenID.Core].
129
+ */
130
+ display_values_supported?: string[];
131
+ /**
132
+ * JSON array containing a list of the Claim Types that the OpenID Provider supports. These Claim Types are described in Section 5.6 of OpenID Connect Core 1.0 [OpenID.Core]. Values defined by this specification are normal, aggregated, and distributed. If omitted, the implementation supports only normal Claims.
133
+ */
134
+ claim_types_supported?: string[];
135
+ /**
136
+ * JSON array containing a list of the Claim Names of the Claims that the OpenID Provider MAY be able to supply values for. Note that for privacy or other reasons, this might not be an exhaustive list.
137
+ */
138
+ claims_supported?: string[];
139
+ /**
140
+ * URL of a page containing human-readable information that developers might want or need to know when using the OpenID Provider. In particular, if the OpenID Provider does not support Dynamic Client Registration, then information on how to register Clients needs to be provided in this documentation.
141
+ */
142
+ service_documentation?: string;
143
+ /**
144
+ * Languages and scripts supported for values in Claims being returned, represented as a JSON array of BCP47 [RFC5646] language tag values. Not all languages and scripts are necessarily supported for all Claim values.
145
+ */
146
+ claims_locales_supported?: string[];
147
+ /**
148
+ * Languages and scripts supported for the user interface, represented as a JSON array of BCP47 [RFC5646] language tag values.
149
+ */
150
+ ui_locales_supported?: string[];
151
+ /**
152
+ * Boolean value specifying whether the OP supports use of the claims parameter, with true indicating support. If omitted, the default value is false.
153
+ */
154
+ claims_parameter_supported?: boolean;
155
+ /**
156
+ * Boolean value specifying whether the OP supports use of the request parameter, with true indicating support. If omitted, the default value is false.
157
+ */
158
+ request_parameter_supported?: boolean;
159
+ /**
160
+ * Boolean value specifying whether the OP supports use of the request_uri parameter, with true indicating support. If omitted, the default value is true.
161
+ */
162
+ request_uri_parameter_supported?: boolean;
163
+ /**
164
+ * Boolean value specifying whether the OP requires any request_uri values used to be pre-registered using the request_uris registration parameter. Pre-registration is REQUIRED when the value is true. If omitted, the default value is false.
165
+ */
166
+ require_request_uri_registration?: boolean;
167
+ /**
168
+ * URL that the OpenID Provider provides to the person registering the Client to read about the OP's requirements on how the Relying Party can use the data provided by the OP. The registration process SHOULD display this URL to the person registering the Client if it is given.
169
+ */
170
+ op_policy_uri?: string;
171
+ /**
172
+ * URL that the OpenID Provider provides to the person registering the Client to read about OpenID Provider's terms of service. The registration process SHOULD display this URL to the person registering the Client if it is given.
173
+ */
174
+ op_tos_uri?: string;
175
+
176
+ }
@@ -212,7 +212,7 @@ export interface ContextUpdateEventDetail<T> {
212
212
  *
213
213
  * @template T The object that is being updated.
214
214
  */
215
- export class ContextUpdateEvent<T extends object> extends ContextEvent<ContextUpdateEventDetail<T>, ContextChangeRecord<T>> {
215
+ export class ContextUpdateEvent<T extends object, U = T> extends ContextEvent<ContextUpdateEventDetail<T>, ContextChangeRecord<U>> {
216
216
  constructor(type: string, updateInfo: ContextUpdateEventDetail<T>) {
217
217
  super(type, updateInfo);
218
218
  }
@@ -1,4 +1,4 @@
1
- import { IClientCertificate, ICertificateIndex, IRequestCertificate } from '../../models/ClientCertificate.js';
1
+ import { HttpCertificate, ICertificateCreateOptions } from '../../models/ClientCertificate.js';
2
2
  import { ContextReadEvent, ContextListEvent, ContextListOptions, ContextListResult, ContextDeleteEvent, ContextDeleteRecord, ContextUpdateEvent, ContextChangeRecord, ContextStateUpdateEvent, ContextStateDeleteEvent } from '../BaseEvents.js';
3
3
  import { ModelEventTypes } from './ModelEventTypes.js';
4
4
 
@@ -8,11 +8,10 @@ export class ClientCertificateEvents {
8
8
  *
9
9
  * @param target A node on which to dispatch the event.
10
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
11
  * @returns Promise resolved to a client certificate model.
13
12
  */
14
- static async read(target: EventTarget, id: string, rev?: string): Promise<IRequestCertificate | undefined> {
15
- const e = new ContextReadEvent<IClientCertificate>(ModelEventTypes.ClientCertificate.read, id, rev);
13
+ static async read(target: EventTarget, id: string): Promise<HttpCertificate | undefined> {
14
+ const e = new ContextReadEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.read, id);
16
15
  target.dispatchEvent(e);
17
16
  return e.detail.result;
18
17
  }
@@ -24,8 +23,8 @@ export class ClientCertificateEvents {
24
23
  * @param opts Query options.
25
24
  * @returns The list result.
26
25
  */
27
- static async list(target: EventTarget, opts?: ContextListOptions): Promise<ContextListResult<ICertificateIndex> | undefined> {
28
- const e = new ContextListEvent<ICertificateIndex>(ModelEventTypes.ClientCertificate.list, opts);
26
+ static async list(target: EventTarget, opts?: ContextListOptions): Promise<ContextListResult<HttpCertificate> | undefined> {
27
+ const e = new ContextListEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.list, opts);
29
28
  target.dispatchEvent(e);
30
29
  return e.detail.result;
31
30
  }
@@ -35,11 +34,10 @@ export class ClientCertificateEvents {
35
34
  *
36
35
  * @param target A node on which to dispatch the event.
37
36
  * @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
37
  * @returns Promise resolved to a new revision after delete.
40
38
  */
41
- static async delete(target: EventTarget, id: string, rev?: string): Promise<ContextDeleteRecord | undefined> {
42
- const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete, id, undefined, rev);
39
+ static async delete(target: EventTarget, id: string): Promise<ContextDeleteRecord | undefined> {
40
+ const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete, id, undefined);
43
41
  target.dispatchEvent(e);
44
42
  return e.detail.result;
45
43
  }
@@ -51,8 +49,8 @@ export class ClientCertificateEvents {
51
49
  * @param item The certificate object.
52
50
  * @returns Promise resolved to the change record
53
51
  */
54
- static async insert(target: EventTarget, item: IClientCertificate): Promise<ContextChangeRecord<ICertificateIndex> | undefined> {
55
- const e = new ContextUpdateEvent<IClientCertificate>(ModelEventTypes.ClientCertificate.insert, { item, });
52
+ static async insert(target: EventTarget, item: ICertificateCreateOptions): Promise<ContextChangeRecord<HttpCertificate> | undefined> {
53
+ const e = new ContextUpdateEvent<ICertificateCreateOptions, HttpCertificate>(ModelEventTypes.ClientCertificate.insert, { item, });
56
54
  target.dispatchEvent(e);
57
55
  return e.detail.result;
58
56
  }
@@ -69,8 +67,8 @@ class StateEvents {
69
67
  * @param target A node on which to dispatch the event.
70
68
  * @param record Change record
71
69
  */
72
- static update(target: EventTarget, record: ContextChangeRecord<ICertificateIndex>): void {
73
- const e = new ContextStateUpdateEvent<ICertificateIndex>(ModelEventTypes.ClientCertificate.State.update, record);
70
+ static update(target: EventTarget, record: ContextChangeRecord<HttpCertificate>): void {
71
+ const e = new ContextStateUpdateEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.State.update, record);
74
72
  target.dispatchEvent(e);
75
73
  }
76
74
 
@@ -10,38 +10,4 @@ export const ModelEventTypes = {
10
10
  delete: 'storestateclientcertificatedelete',
11
11
  }),
12
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
13
  }
@@ -1,7 +1,5 @@
1
1
  import { ClientCertificateEvents } from './ClientCertificateEvents.js';
2
- import { ProjectEvents } from './ProjectEvents.js';
3
2
 
4
3
  export const ModelEvents = Object.freeze({
5
- Project: ProjectEvents,
6
4
  ClientCertificate: ClientCertificateEvents,
7
5
  });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Converts base64 string to Uint8Array.
3
+ *
4
+ * @returns The restored array view.
5
+ */
6
+ export function base64ToBuffer(str: string): Uint8Array {
7
+ const asciiString = atob(str);
8
+ return new Uint8Array([...asciiString].map((char) => char.charCodeAt(0)));
9
+ }
10
+
11
+ /**
12
+ * Converts incoming data to base64 string.
13
+ *
14
+ * @returns Safe to store string.
15
+ */
16
+ export function bufferToBase64(view: Buffer | Uint8Array): string {
17
+ const str = view.reduce(
18
+ (data, byte) => data + String.fromCharCode(byte),
19
+ ''
20
+ );
21
+ return btoa(str);
22
+ }
23
+
24
+ /**
25
+ * Reads file as ArrayBuffer
26
+ */
27
+ export function fileToBuffer(blob: Blob): Promise<Uint8Array> {
28
+ return new Promise((resolve, reject) => {
29
+ const reader = new FileReader();
30
+ reader.onload = (): void => { resolve(new Uint8Array(reader.result as ArrayBuffer)); };
31
+ /* istanbul ignore next */
32
+ reader.onerror = (): void => { reject(new Error('Unable to read file')); };
33
+ reader.readAsArrayBuffer(blob);
34
+ });
35
+ }
36
+
37
+ /**
38
+ * Reads file as string
39
+ */
40
+ export function fileToString(blob: Blob): Promise<string> {
41
+ return new Promise((resolve, reject) => {
42
+ const reader = new FileReader();
43
+ reader.onload = (): void => { resolve(reader.result as string); };
44
+ /* istanbul ignore next */
45
+ reader.onerror = (): void => { reject(new Error('Unable to read file')); };
46
+ reader.readAsText(blob);
47
+ });
48
+ }
@@ -1,3 +1,5 @@
1
+ import { HttpCertificate } from "./ClientCertificate.js";
2
+
1
3
  export interface IBasicAuthorization {
2
4
  /**
3
5
  * User name value.
@@ -68,12 +70,9 @@ export interface IOAuth1Authorization {
68
70
  */
69
71
  export interface ICCAuthorization {
70
72
  /**
71
- * The ID of the certificate to use.
72
- * Because the certificates are stored by the application
73
- * this configuration only returns an ID of the certificate
74
- * to use when making the request.
73
+ * The certificate object to use with the HTTP request.
75
74
  */
76
- id: string;
75
+ certificate?: HttpCertificate;
77
76
  }
78
77
 
79
78
  export declare interface IOAuth2CustomParameter {
@@ -1,54 +1,124 @@
1
+ import { base64ToBuffer, bufferToBase64 } from '../lib/Buffer.js';
2
+ import v4 from '../lib/uuid.js';
3
+
1
4
  export type CertificateType = 'p12' | 'pem';
2
5
 
6
+ export const Kind = 'Core#Certificate';
7
+
8
+ export type CertificateDataFormat = string | ArrayBuffer | Buffer | Uint8Array;
9
+
3
10
  /**
4
11
  * Represents a single certificate object (cert/key)
5
12
  */
6
- export interface ICertificate {
13
+ export interface ICertificateData {
7
14
  /**
8
15
  * The certificate to use.
9
16
  * The `p12` type certificate must be a Buffer.
10
17
  */
11
- data: string|ArrayBuffer|Buffer|Uint8Array;
18
+ data: CertificateDataFormat;
12
19
  /**
13
20
  * A passphrase to use to unlock the certificate.
14
21
  */
15
22
  passphrase?: string;
16
23
  /**
17
- * The original data type of the certificate. This is used by the data store
24
+ * The original data type of the certificate. This is only used internally by the data store
18
25
  * to move between buffers and string values stored in the store.
19
- * By any means, outside the internal procedure of the data store this
20
- * filed is always `undefined` and the `data` contains the original data format.
26
+ * Outside the internal procedure of the data store this
27
+ * is always `undefined` and the `data` contains the original data format.
21
28
  */
22
- type?: string;
29
+ type?: 'buffer';
23
30
  }
24
31
 
25
- /**
26
- * Represents a complete certificate configuration required to make
27
- * a HTTP request.
28
- */
29
- export interface IRequestCertificate {
30
- /**
32
+ export interface ICertificate {
33
+ kind: typeof Kind;
34
+ /**
35
+ * The data store key to refer.
36
+ */
37
+ key: string;
38
+ /**
39
+ * Custom name of the certificate.
40
+ */
41
+ name: string;
42
+ /**
43
+ * Timestamp when the certificate was inserted into the data store.
44
+ * Required when returning a result. Auto-generated when inserting, if missing.
45
+ */
46
+ created?: number;
47
+ /**
31
48
  * Certificate type. Either `p12` or `pem`.
32
49
  */
33
50
  type: CertificateType;
34
51
  /**
35
52
  * Certificate or list of certificates to use.
36
53
  */
37
- cert: ICertificate|ICertificate[];
54
+ cert: ICertificateData;
55
+ }
56
+
57
+ export interface IP12Certificate extends ICertificate {
58
+ type: 'p12';
59
+ }
60
+
61
+ /**
62
+ * Represents a complete certificate configuration required to make
63
+ * an HTTP request.
64
+ */
65
+ export interface IPemCertificate extends ICertificate {
66
+ type: 'pem';
38
67
  /**
39
- * Key for the `pem` type certificate.
68
+ * The key for the `pem` type certificate.
40
69
  */
41
- key?: ICertificate|ICertificate[];
70
+ certKey: ICertificateData;
71
+ }
72
+
73
+ export type HttpCertificate = IP12Certificate | IPemCertificate;
74
+
75
+ export interface IPemCreateOptions {
76
+ type: 'p12';
77
+ /**
78
+ * The certificate contents.
79
+ */
80
+ cert: CertificateDataFormat;
81
+ /**
82
+ * The key contents.
83
+ */
84
+ key: CertificateDataFormat;
85
+ /**
86
+ * Optional name for the certificate.
87
+ */
88
+ name?: string;
89
+ /**
90
+ * Optional passphrase for the key.
91
+ */
92
+ passphrase?: string;
42
93
  }
43
94
 
95
+ export interface IP12CreateOptions {
96
+ type: 'pem';
97
+ /**
98
+ * The certificate contents.
99
+ */
100
+ cert: CertificateDataFormat;
101
+ /**
102
+ * Optional name for the certificate.
103
+ */
104
+ name?: string;
105
+ /**
106
+ * Optional passphrase for the certificate.
107
+ */
108
+ passphrase?: string;
109
+ }
110
+
111
+ export type ICertificateCreateOptions = IPemCreateOptions | IP12CreateOptions;
112
+
44
113
  /**
45
- * Client certificate index definition for listings.
114
+ * A class that represents a certificate in the system
46
115
  */
47
- export interface ICertificateIndex {
116
+ export class Certificate {
117
+ kind = Kind;
48
118
  /**
49
- * Certificate type. Either `p12` or `pem`.
119
+ * The data store key to refer.
50
120
  */
51
- type: CertificateType;
121
+ key: string;
52
122
  /**
53
123
  * Custom name of the certificate.
54
124
  */
@@ -58,11 +128,140 @@ export interface ICertificateIndex {
58
128
  * Required when returning a result. Auto-generated when inserting, if missing.
59
129
  */
60
130
  created?: number;
61
- }
131
+ /**
132
+ * Certificate type. Either `p12` or `pem`.
133
+ */
134
+ type: CertificateType;
135
+ /**
136
+ * Certificate or list of certificates to use.
137
+ */
138
+ cert: ICertificateData;
139
+ /**
140
+ * The key for the `pem` type certificate.
141
+ */
142
+ certKey?: ICertificateData;
143
+
144
+ /**
145
+ * Creates a new certificate instance for a PEM key
146
+ *
147
+ * @param pem The certificate contents
148
+ * @param key The key contents
149
+ * @param name The certificate name
150
+ * @param keyPassphrase The key passphrase
151
+ */
152
+ static fromPem(pem: CertificateDataFormat, key: CertificateDataFormat, name = 'New PEM certificate', keyPassphrase?: string): Certificate {
153
+ const init: IPemCertificate = {
154
+ kind: Kind,
155
+ cert: {
156
+ data: pem,
157
+ },
158
+ certKey: {
159
+ data: key,
160
+ },
161
+ key: v4(),
162
+ name,
163
+ type: 'pem',
164
+ };
165
+ if (keyPassphrase) {
166
+ init.certKey.passphrase = keyPassphrase;
167
+ }
168
+ return new Certificate(init);
169
+ }
62
170
 
63
- /**
64
- * A base client certificate object used in API Client to create / list objects.
65
- * This is not a data entity but rather something used to outside of a context of a data store.
66
- */
67
- export interface IClientCertificate extends IRequestCertificate, ICertificateIndex {
171
+ /**
172
+ * Creates a new certificate instance for a P12 key
173
+ *
174
+ * @param cert The certificate contents
175
+ * @param name The certificate name
176
+ * @param passphrase The key passphrase
177
+ */
178
+ static fromP12(cert: CertificateDataFormat, name = 'New P12 certificate', passphrase?: string): Certificate {
179
+ const init: IP12Certificate = {
180
+ kind: Kind,
181
+ cert: {
182
+ data: cert,
183
+ },
184
+ key: v4(),
185
+ name,
186
+ type: 'p12',
187
+ };
188
+ if (passphrase) {
189
+ init.cert.passphrase = passphrase;
190
+ }
191
+ return new Certificate(init);
192
+ }
193
+
194
+ constructor(certificate: HttpCertificate) {
195
+ const { type, cert, key=v4(), name='', created } = certificate;
196
+ this.key = key;
197
+ this.name = name;
198
+ this.type = type;
199
+ this.cert = this.fromStore(cert);
200
+ if (typeof created === 'number') {
201
+ this.created = created;
202
+ }
203
+ if (type === 'pem') {
204
+ this.certKey = this.fromStore(certificate.certKey);
205
+ }
206
+ }
207
+
208
+ /**
209
+ * When needed it reads the certificate's original format.
210
+ * @param data The certificate data.
211
+ * @returns The restored certificate.
212
+ */
213
+ fromStore(data: ICertificateData): ICertificateData {
214
+ if (data.type) {
215
+ delete data.type;
216
+ const content = data.data as string;
217
+ data.data = base64ToBuffer(content);
218
+ }
219
+ return data;
220
+ }
221
+
222
+ /**
223
+ * Prepares certificate object to be stored in the data store.
224
+ * If the `data` property is not string then it assumes buffer (either
225
+ * Node's or ArrayBuffer). In this case it converts buffer to base64 string.
226
+ * It also adds `type` property set to `buffer` for the `fromStore()`
227
+ * function to recognize what to do with the data.
228
+ *
229
+ * Note, for optimization, PEM keys should be strings as the content of the
230
+ * certificate is already a base62 string. To spare double base64 conversion
231
+ * use string data.
232
+ *
233
+ * @param data The certificate data object.
234
+ * @throws When data is not set
235
+ */
236
+ toStore(data: ICertificateData): ICertificateData {
237
+ if (!data) {
238
+ throw new Error('Certificate data is missing.');
239
+ }
240
+ if (!data.data) {
241
+ throw new Error('Certificate content not set.');
242
+ }
243
+ if (typeof data.data !== 'string') {
244
+ data.type = 'buffer';
245
+ const buff = data.data as Buffer;
246
+ data.data = bufferToBase64(buff);
247
+ }
248
+ return data;
249
+ }
250
+
251
+ toJSON(): HttpCertificate {
252
+ const result: IP12Certificate = {
253
+ kind: Kind,
254
+ key: this.key,
255
+ cert: this.toStore(this.cert),
256
+ name: this.name,
257
+ type: 'p12',
258
+ };
259
+
260
+ if (this.type === 'pem') {
261
+ const typed = (result as unknown) as IPemCertificate;
262
+ typed.certKey = this.toStore(this.certKey!);
263
+ }
264
+
265
+ return result;
266
+ }
68
267
  }