@api-client/core 0.6.23 → 0.6.24

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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import { ARCCertificateIndex, RequestCertificate } from './legacy/models/ClientCertificate.js';
2
3
  export declare type CertificateType = 'p12' | 'pem';
3
4
  export declare const Kind = "Core#Certificate";
4
5
  export declare type CertificateDataFormat = string | ArrayBuffer | Buffer | Uint8Array;
@@ -144,13 +145,20 @@ export declare class Certificate {
144
145
  * @param passphrase The key passphrase
145
146
  */
146
147
  static fromP12(cert: CertificateDataFormat, name?: string, passphrase?: string): Certificate;
148
+ /**
149
+ * Creates a certificate object from the ARC's legacy certificate definition.
150
+ *
151
+ * @param index The legacy certificate index object. If it has set `_id` it will be used as the `key`.
152
+ * @param index The certificate data object as read from the data store. Do not restore the data to its original format.
153
+ */
154
+ static fromLegacy(index: ARCCertificateIndex, cert: RequestCertificate): Certificate;
147
155
  constructor(certificate: HttpCertificate);
148
156
  /**
149
157
  * When needed it reads the certificate's original format.
150
158
  * @param data The certificate data.
151
159
  * @returns The restored certificate.
152
160
  */
153
- fromStore(data: ICertificateData): ICertificateData;
161
+ static fromStore(data: ICertificateData): ICertificateData;
154
162
  /**
155
163
  * Prepares certificate object to be stored in the data store.
156
164
  * If the `data` property is not string then it assumes buffer (either
@@ -165,6 +173,6 @@ export declare class Certificate {
165
173
  * @param data The certificate data object.
166
174
  * @throws When data is not set
167
175
  */
168
- toStore(data: ICertificateData): ICertificateData;
176
+ static toStore(data: ICertificateData): ICertificateData;
169
177
  toJSON(): HttpCertificate;
170
178
  }
@@ -79,17 +79,55 @@ export class Certificate {
79
79
  }
80
80
  return new Certificate(init);
81
81
  }
82
+ /**
83
+ * Creates a certificate object from the ARC's legacy certificate definition.
84
+ *
85
+ * @param index The legacy certificate index object. If it has set `_id` it will be used as the `key`.
86
+ * @param index The certificate data object as read from the data store. Do not restore the data to its original format.
87
+ */
88
+ static fromLegacy(index, cert) {
89
+ const { name = '', type, created = Date.now(), _id = v4() } = index;
90
+ if (type === 'pem') {
91
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
92
+ const key = Array.isArray(cert.key) ? cert.key[0] : cert.key;
93
+ if (!key) {
94
+ throw new Error(`Unable to create a PEM certificate without the key.`);
95
+ }
96
+ const init = {
97
+ kind: Kind,
98
+ cert: data,
99
+ certKey: key,
100
+ key: _id,
101
+ name,
102
+ type: 'pem',
103
+ created,
104
+ };
105
+ return new Certificate(init);
106
+ }
107
+ else if (type === 'p12') {
108
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
109
+ const init = {
110
+ kind: Kind,
111
+ cert: data,
112
+ key: _id,
113
+ name,
114
+ type: 'p12',
115
+ };
116
+ return new Certificate(init);
117
+ }
118
+ throw new Error(`Unable to create a certificate. Unknown type: ${type}.`);
119
+ }
82
120
  constructor(certificate) {
83
121
  const { type, cert, key = v4(), name = '', created } = certificate;
84
122
  this.key = key;
85
123
  this.name = name;
86
124
  this.type = type;
87
- this.cert = this.fromStore(cert);
125
+ this.cert = Certificate.fromStore(cert);
88
126
  if (typeof created === 'number') {
89
127
  this.created = created;
90
128
  }
91
129
  if (type === 'pem') {
92
- this.certKey = this.fromStore(certificate.certKey);
130
+ this.certKey = Certificate.fromStore(certificate.certKey);
93
131
  }
94
132
  }
95
133
  /**
@@ -97,7 +135,7 @@ export class Certificate {
97
135
  * @param data The certificate data.
98
136
  * @returns The restored certificate.
99
137
  */
100
- fromStore(data) {
138
+ static fromStore(data) {
101
139
  if (data.type) {
102
140
  delete data.type;
103
141
  const content = data.data;
@@ -119,7 +157,7 @@ export class Certificate {
119
157
  * @param data The certificate data object.
120
158
  * @throws When data is not set
121
159
  */
122
- toStore(data) {
160
+ static toStore(data) {
123
161
  if (!data) {
124
162
  throw new Error('Certificate data is missing.');
125
163
  }
@@ -137,13 +175,13 @@ export class Certificate {
137
175
  const result = {
138
176
  kind: Kind,
139
177
  key: this.key,
140
- cert: this.toStore(this.cert),
178
+ cert: Certificate.toStore(this.cert),
141
179
  name: this.name,
142
180
  type: 'p12',
143
181
  };
144
182
  if (this.type === 'pem' && this.certKey) {
145
183
  const typed = result;
146
- typed.certKey = this.toStore(this.certKey);
184
+ typed.certKey = Certificate.toStore(this.certKey);
147
185
  }
148
186
  return result;
149
187
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCertificate.js","sourceRoot":"","sources":["../../../src/models/ClientCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAIhC,MAAM,CAAC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AA2GvC;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,IAAI,GAAG,IAAI,CAAC;IACZ;;OAEG;IACH,GAAG,CAAS;IACZ;;OAEG;IACH,IAAI,CAAS;IACb;;;OAGG;IACH,OAAO,CAAU;IACjB;;OAEG;IACH,IAAI,CAAkB;IACtB;;OAEG;IACH,IAAI,CAAmB;IACvB;;OAEG;IACH,OAAO,CAAoB;IAE3B;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,GAA0B,EAAE,GAA0B,EAAE,IAAI,GAAG,qBAAqB,EAAE,aAAsB;QACzH,MAAM,IAAI,GAAoB;YAC5B,IAAI,EAAE,IAAI;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,GAAG;aACV;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,GAAG;aACV;YACD,GAAG,EAAE,EAAE,EAAE;YACT,IAAI;YACJ,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,IAAI,aAAa,EAAE;YACjB,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,aAAa,CAAC;SACzC;QACD,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IAC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Ac,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;SAClC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAoB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACpC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,KAAK;SACZ,CAAC;QAEF,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE;YACvC,MAAM,KAAK,GAAI,MAAqC,CAAC;YACrD,KAAK,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACnD;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.6.23",
4
+ "version": "0.6.24",
5
5
  "license": "Apache-2.0",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -1,5 +1,6 @@
1
1
  import { base64ToBuffer, bufferToBase64 } from '../lib/Buffer.js';
2
2
  import v4 from '../lib/uuid.js';
3
+ import { Certificate as LegacyCertificate, ARCCertificateIndex, RequestCertificate } from './legacy/models/ClientCertificate.js';
3
4
 
4
5
  export type CertificateType = 'p12' | 'pem';
5
6
 
@@ -77,15 +78,15 @@ export interface IPemCreateOptions {
77
78
  /**
78
79
  * The certificate contents.
79
80
  */
80
- cert: CertificateDataFormat;
81
+ cert: CertificateDataFormat;
81
82
  /**
82
83
  * The key contents.
83
84
  */
84
- key: CertificateDataFormat;
85
+ key: CertificateDataFormat;
85
86
  /**
86
87
  * Optional name for the certificate.
87
88
  */
88
- name?: string;
89
+ name?: string;
89
90
  /**
90
91
  * Optional passphrase for the key.
91
92
  */
@@ -101,7 +102,7 @@ export interface IP12CreateOptions {
101
102
  /**
102
103
  * Optional name for the certificate.
103
104
  */
104
- name?: string;
105
+ name?: string;
105
106
  /**
106
107
  * Optional passphrase for the certificate.
107
108
  */
@@ -140,7 +141,7 @@ export class Certificate {
140
141
  * The key for the `pem` type certificate.
141
142
  */
142
143
  certKey?: ICertificateData;
143
-
144
+
144
145
  /**
145
146
  * Creates a new certificate instance for a PEM key
146
147
  *
@@ -191,17 +192,55 @@ export class Certificate {
191
192
  return new Certificate(init);
192
193
  }
193
194
 
195
+ /**
196
+ * Creates a certificate object from the ARC's legacy certificate definition.
197
+ *
198
+ * @param index The legacy certificate index object. If it has set `_id` it will be used as the `key`.
199
+ * @param index The certificate data object as read from the data store. Do not restore the data to its original format.
200
+ */
201
+ static fromLegacy(index: ARCCertificateIndex, cert: RequestCertificate): Certificate {
202
+ const { name = '', type, created = Date.now(), _id = v4() } = index;
203
+ if (type === 'pem') {
204
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
205
+ const key = Array.isArray(cert.key) ? cert.key[0] : cert.key as LegacyCertificate;
206
+ if (!key) {
207
+ throw new Error(`Unable to create a PEM certificate without the key.`);
208
+ }
209
+ const init: IPemCertificate = {
210
+ kind: Kind,
211
+ cert: data as ICertificateData, // these are compatible.
212
+ certKey: key as ICertificateData,
213
+ key: _id,
214
+ name,
215
+ type: 'pem',
216
+ created,
217
+ };
218
+ return new Certificate(init);
219
+ } else if (type === 'p12') {
220
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
221
+ const init: IP12Certificate = {
222
+ kind: Kind,
223
+ cert: data as ICertificateData, // these are compatible.
224
+ key: _id,
225
+ name,
226
+ type: 'p12',
227
+ };
228
+ return new Certificate(init);
229
+ }
230
+ throw new Error(`Unable to create a certificate. Unknown type: ${type}.`);
231
+ }
232
+
194
233
  constructor(certificate: HttpCertificate) {
195
- const { type, cert, key=v4(), name='', created } = certificate;
234
+ const { type, cert, key = v4(), name = '', created } = certificate;
196
235
  this.key = key;
197
236
  this.name = name;
198
237
  this.type = type;
199
- this.cert = this.fromStore(cert);
238
+ this.cert = Certificate.fromStore(cert);
200
239
  if (typeof created === 'number') {
201
240
  this.created = created;
202
241
  }
203
242
  if (type === 'pem') {
204
- this.certKey = this.fromStore(certificate.certKey);
243
+ this.certKey = Certificate.fromStore(certificate.certKey);
205
244
  }
206
245
  }
207
246
 
@@ -210,7 +249,7 @@ export class Certificate {
210
249
  * @param data The certificate data.
211
250
  * @returns The restored certificate.
212
251
  */
213
- fromStore(data: ICertificateData): ICertificateData {
252
+ static fromStore(data: ICertificateData): ICertificateData {
214
253
  if (data.type) {
215
254
  delete data.type;
216
255
  const content = data.data as string;
@@ -233,7 +272,7 @@ export class Certificate {
233
272
  * @param data The certificate data object.
234
273
  * @throws When data is not set
235
274
  */
236
- toStore(data: ICertificateData): ICertificateData {
275
+ static toStore(data: ICertificateData): ICertificateData {
237
276
  if (!data) {
238
277
  throw new Error('Certificate data is missing.');
239
278
  }
@@ -252,14 +291,14 @@ export class Certificate {
252
291
  const result: IP12Certificate = {
253
292
  kind: Kind,
254
293
  key: this.key,
255
- cert: this.toStore(this.cert),
294
+ cert: Certificate.toStore(this.cert),
256
295
  name: this.name,
257
296
  type: 'p12',
258
297
  };
259
298
 
260
299
  if (this.type === 'pem' && this.certKey) {
261
300
  const typed = (result as unknown) as IPemCertificate;
262
- typed.certKey = this.toStore(this.certKey);
301
+ typed.certKey = Certificate.toStore(this.certKey);
263
302
  }
264
303
 
265
304
  return result;