Skip to content

Commit 4d2aa8e

Browse files
authored
Merge pull request #61 from kaleido-io/identity
Add updateIdentity and deleteData
2 parents fbccc43 + aa677ab commit 4d2aa8e

File tree

6 files changed

+806
-34
lines changed

6 files changed

+806
-34
lines changed

lib/firefly.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ import {
7373
FireFlyVerifierResolveResponse,
7474
FireFlyTokenApprovalRequest,
7575
FireFlyNamespaceResponse,
76+
FireFlyUpdateIdentityRequest,
77+
FireFlyReplaceOptions,
78+
FireFlyUpdateOptions,
79+
FireFlyDeleteOptions,
7680
} from './interfaces';
7781
import { FireFlyWebSocket, FireFlyWebSocketCallback } from './websocket';
7882
import HttpBase, { mapConfig } from './http';
@@ -93,10 +97,10 @@ export default class FireFly extends HttpBase {
9397
}
9498

9599
getIdentity(
96-
nameOrId: string,
100+
id: string,
97101
options?: FireFlyGetOptions,
98102
): Promise<FireFlyIdentityResponse | undefined> {
99-
return this.getOne<FireFlyIdentityResponse>(`/identities/${nameOrId}`, options);
103+
return this.getOne<FireFlyIdentityResponse>(`/identities/${id}`, options);
100104
}
101105

102106
createIdentity(
@@ -106,20 +110,42 @@ export default class FireFly extends HttpBase {
106110
return this.createOne<FireFlyIdentityResponse>(`/identities`, identity, options);
107111
}
108112

113+
updateIdentity(
114+
id: string,
115+
update: FireFlyUpdateIdentityRequest,
116+
options?: FireFlyUpdateOptions,
117+
): Promise<FireFlyIdentityResponse> {
118+
return this.updateOne<FireFlyIdentityResponse>(`/identities/${id}`, update, options);
119+
}
120+
109121
getOrganizations(
110122
filter?: FireFlyOrganizationFilter,
111123
options?: FireFlyGetOptions,
112124
): Promise<FireFlyOrganizationResponse[]> {
113125
return this.getMany<FireFlyOrganizationResponse[]>('/network/organizations', filter, options);
114126
}
115127

128+
getOrganization(
129+
nameOrId: string,
130+
options?: FireFlyGetOptions,
131+
): Promise<FireFlyIdentityResponse | undefined> {
132+
return this.getOne<FireFlyIdentityResponse>(`/network/organizations/${nameOrId}`, options);
133+
}
134+
116135
getNodes(
117136
filter?: FireFlyNodeFilter,
118137
options?: FireFlyGetOptions,
119138
): Promise<FireFlyNodeResponse[]> {
120139
return this.getMany<FireFlyNodeResponse[]>('/network/nodes', filter, options);
121140
}
122141

142+
getNode(
143+
nameOrId: string,
144+
options?: FireFlyGetOptions,
145+
): Promise<FireFlyIdentityResponse | undefined> {
146+
return this.getOne<FireFlyIdentityResponse>(`/network/nodes/${nameOrId}`, options);
147+
}
148+
123149
getVerifiers(
124150
namespace?: string,
125151
filter?: FireFlyVerifierFilter,
@@ -175,12 +201,15 @@ export default class FireFly extends HttpBase {
175201
return this.getMany<FireFlySubscriptionResponse[]>('/subscriptions', filter, options);
176202
}
177203

178-
replaceSubscription(sub: FireFlySubscriptionRequest): Promise<FireFlySubscriptionResponse> {
179-
return this.replaceOne<FireFlySubscriptionResponse>('/subscriptions', sub);
204+
replaceSubscription(
205+
sub: FireFlySubscriptionRequest,
206+
options?: FireFlyReplaceOptions,
207+
): Promise<FireFlySubscriptionResponse> {
208+
return this.replaceOne<FireFlySubscriptionResponse>('/subscriptions', sub, options);
180209
}
181210

182-
async deleteSubscription(subId: string) {
183-
await this.deleteOne(`/subscriptions/${subId}`);
211+
async deleteSubscription(subId: string, options?: FireFlyDeleteOptions) {
212+
await this.deleteOne(`/subscriptions/${subId}`, options);
184213
}
185214

186215
getData(id: string, options?: FireFlyGetOptions): Promise<FireFlyDataResponse | undefined> {
@@ -248,6 +277,10 @@ export default class FireFly extends HttpBase {
248277
return this.createOne<FireFlyDataResponse>(`/data/${id}/blob/publish`, {}, options);
249278
}
250279

280+
async deleteData(id: string, options?: FireFlyDeleteOptions) {
281+
await this.deleteOne(`/data/${id}`, options);
282+
}
283+
251284
getBatches(
252285
filter?: FireFlyBatchFilter,
253286
options?: FireFlyGetOptions,

lib/http.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,38 @@ import {
55
FireFlyCreateOptions,
66
FireFlyGetOptions,
77
FireFlyError,
8+
FireFlyReplaceOptions,
9+
FireFlyUpdateOptions,
10+
FireFlyDeleteOptions,
811
} from './interfaces';
912

1013
function isSuccess(status: number) {
1114
return status >= 200 && status < 300;
1215
}
1316

1417
export function mapConfig(
15-
options: FireFlyGetOptions | FireFlyCreateOptions | undefined,
18+
options:
19+
| FireFlyGetOptions
20+
| FireFlyUpdateOptions
21+
| FireFlyReplaceOptions
22+
| FireFlyCreateOptions
23+
| FireFlyDeleteOptions
24+
| undefined,
1625
params?: any,
1726
): AxiosRequestConfig {
18-
return {
27+
const config: AxiosRequestConfig = {
1928
...options?.requestConfig,
20-
params: {
21-
...params,
22-
confirm: options?.confirm,
23-
},
29+
params,
2430
};
31+
if (options !== undefined) {
32+
if ('confirm' in options) {
33+
config.params = {
34+
...config.params,
35+
confirm: options.confirm,
36+
};
37+
}
38+
}
39+
return config;
2540
}
2641

2742
export default class HttpBase {
@@ -92,13 +107,18 @@ export default class HttpBase {
92107
return response.data;
93108
}
94109

95-
protected async replaceOne<T>(url: string, data: any) {
96-
const response = await this.wrapError(this.http.put<T>(url, data));
110+
protected async updateOne<T>(url: string, data: any, options?: FireFlyUpdateOptions) {
111+
const response = await this.wrapError(this.http.patch<T>(url, data, mapConfig(options)));
112+
return response.data;
113+
}
114+
115+
protected async replaceOne<T>(url: string, data: any, options?: FireFlyReplaceOptions) {
116+
const response = await this.wrapError(this.http.put<T>(url, data, mapConfig(options)));
97117
return response.data;
98118
}
99119

100-
protected async deleteOne<T>(url: string) {
101-
await this.wrapError(this.http.delete<T>(url));
120+
protected async deleteOne<T>(url: string, options?: FireFlyDeleteOptions) {
121+
await this.wrapError(this.http.delete<T>(url, mapConfig(options)));
102122
}
103123

104124
onError(handler: (err: FireFlyError) => void) {

lib/interfaces.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ export class FireFlyError extends Error {
2121
}
2222
}
2323

24-
export interface FireFlyGetOptions {
25-
confirm: undefined;
24+
interface FireFlyBaseHttpOptions {
2625
requestConfig?: AxiosRequestConfig;
2726
}
2827

29-
export interface FireFlyCreateOptions {
28+
export interface FireFlyGetOptions extends FireFlyBaseHttpOptions {}
29+
export interface FireFlyUpdateOptions extends FireFlyBaseHttpOptions {}
30+
export interface FireFlyReplaceOptions extends FireFlyBaseHttpOptions {}
31+
export interface FireFlyDeleteOptions extends FireFlyBaseHttpOptions {}
32+
33+
export interface FireFlyCreateOptions extends FireFlyBaseHttpOptions {
3034
confirm?: boolean;
31-
requestConfig?: AxiosRequestConfig;
3235
}
3336

3437
export interface FireFlyOptionsInput {
@@ -80,6 +83,8 @@ export type FireFlyVerifierFilter = operations['getVerifiers']['parameters']['qu
8083

8184
export type FireFlyIdentityRequest =
8285
operations['postNewIdentity']['requestBody']['content']['application/json'];
86+
export type FireFlyUpdateIdentityRequest =
87+
operations['patchUpdateIdentity']['requestBody']['content']['application/json'];
8388

8489
export type FireFlyIdentityResponse = Required<
8590
operations['getIdentityByID']['responses']['200']['content']['application/json']

0 commit comments

Comments
 (0)