@ogcio/building-blocks-sdk 0.1.5 → 0.1.7
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.
- package/.azure/pipeline.yaml +16 -0
- package/.azure/templates/pnpm-install.yaml +1 -1
- package/README.md +1 -1
- package/biome.jsonc +2 -1
- package/dist/__tests__/client/utils/client-utils.test.js +6 -6
- package/dist/__tests__/client/utils/client-utils.test.js.map +1 -1
- package/dist/client/base-client.d.ts +4 -2
- package/dist/client/base-client.d.ts.map +1 -1
- package/dist/client/base-client.js +7 -1
- package/dist/client/base-client.js.map +1 -1
- package/dist/client/clients/featureFlags/index.d.ts.map +1 -1
- package/dist/client/clients/featureFlags/index.js +2 -2
- package/dist/client/clients/featureFlags/index.js.map +1 -1
- package/dist/client/clients/journey/index.d.ts +2 -2
- package/dist/client/clients/journey/index.d.ts.map +1 -1
- package/dist/client/clients/journey/index.js +21 -21
- package/dist/client/clients/journey/index.js.map +1 -1
- package/dist/client/clients/journey/schema.d.ts +1 -1
- package/dist/client/clients/journey/schema.d.ts.map +1 -1
- package/dist/client/clients/messaging/index.d.ts.map +1 -1
- package/dist/client/clients/messaging/index.js +29 -29
- package/dist/client/clients/messaging/index.js.map +1 -1
- package/dist/client/clients/payments/index.d.ts +64 -35
- package/dist/client/clients/payments/index.d.ts.map +1 -1
- package/dist/client/clients/payments/index.js +34 -25
- package/dist/client/clients/payments/index.js.map +1 -1
- package/dist/client/clients/payments/schema.d.ts +81 -18
- package/dist/client/clients/payments/schema.d.ts.map +1 -1
- package/dist/client/clients/profile/index.d.ts.map +1 -1
- package/dist/client/clients/profile/index.js +13 -13
- package/dist/client/clients/profile/index.js.map +1 -1
- package/dist/client/clients/scheduler/index.js +1 -1
- package/dist/client/clients/scheduler/index.js.map +1 -1
- package/dist/client/clients/upload/index.d.ts.map +1 -1
- package/dist/client/clients/upload/index.js +7 -7
- package/dist/client/clients/upload/index.js.map +1 -1
- package/dist/client/utils/client-utils.d.ts +3 -2
- package/dist/client/utils/client-utils.d.ts.map +1 -1
- package/dist/client/utils/client-utils.js +10 -3
- package/dist/client/utils/client-utils.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +16 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/client/utils/client-utils.test.ts +6 -6
- package/src/client/base-client.ts +14 -2
- package/src/client/clients/featureFlags/index.ts +5 -2
- package/src/client/clients/journey/index.ts +42 -42
- package/src/client/clients/journey/open-api-definition.json +41 -6
- package/src/client/clients/journey/schema.ts +1 -1
- package/src/client/clients/messaging/index.ts +58 -58
- package/src/client/clients/payments/index.ts +65 -50
- package/src/client/clients/payments/open-api-definition.json +176 -101
- package/src/client/clients/payments/schema.ts +81 -18
- package/src/client/clients/profile/index.ts +26 -26
- package/src/client/clients/scheduler/index.ts +2 -2
- package/src/client/clients/upload/index.ts +14 -14
- package/src/client/utils/client-utils.ts +20 -2
- package/src/index.ts +17 -12
- package/src/types/index.ts +18 -1
|
@@ -125,23 +125,6 @@ export interface paths {
|
|
|
125
125
|
id: string;
|
|
126
126
|
name: string;
|
|
127
127
|
type: "banktransfer" | "openbanking" | "stripe" | "realex" | "worldpay";
|
|
128
|
-
data: {
|
|
129
|
-
iban: string;
|
|
130
|
-
accountHolderName: string;
|
|
131
|
-
} | {
|
|
132
|
-
iban: string;
|
|
133
|
-
accountHolderName: string;
|
|
134
|
-
} | {
|
|
135
|
-
livePublishableKey: string;
|
|
136
|
-
liveSecretKey: string;
|
|
137
|
-
webhookSigningKey?: string;
|
|
138
|
-
} | {
|
|
139
|
-
merchantCode: string;
|
|
140
|
-
installationId: string;
|
|
141
|
-
} | {
|
|
142
|
-
merchantId: string;
|
|
143
|
-
sharedSecret: string;
|
|
144
|
-
};
|
|
145
128
|
status: "connected" | "disconnected";
|
|
146
129
|
}[];
|
|
147
130
|
metadata?: {
|
|
@@ -349,6 +332,7 @@ export interface paths {
|
|
|
349
332
|
id: string;
|
|
350
333
|
name: string;
|
|
351
334
|
type: "banktransfer" | "openbanking" | "stripe" | "realex" | "worldpay";
|
|
335
|
+
status: "connected" | "disconnected";
|
|
352
336
|
data: {
|
|
353
337
|
iban: string;
|
|
354
338
|
accountHolderName: string;
|
|
@@ -366,7 +350,6 @@ export interface paths {
|
|
|
366
350
|
merchantId: string;
|
|
367
351
|
sharedSecret: string;
|
|
368
352
|
};
|
|
369
|
-
status: "connected" | "disconnected";
|
|
370
353
|
};
|
|
371
354
|
metadata?: {
|
|
372
355
|
/** @description Object containing the links to the related endpoints */
|
|
@@ -877,6 +860,86 @@ export interface paths {
|
|
|
877
860
|
patch?: never;
|
|
878
861
|
trace?: never;
|
|
879
862
|
};
|
|
863
|
+
"/api/v1/requests/external-info": {
|
|
864
|
+
parameters: {
|
|
865
|
+
query?: never;
|
|
866
|
+
header?: never;
|
|
867
|
+
path?: never;
|
|
868
|
+
cookie?: never;
|
|
869
|
+
};
|
|
870
|
+
get: {
|
|
871
|
+
parameters: {
|
|
872
|
+
query?: {
|
|
873
|
+
offset?: number;
|
|
874
|
+
limit?: number;
|
|
875
|
+
};
|
|
876
|
+
header?: never;
|
|
877
|
+
path?: never;
|
|
878
|
+
cookie?: never;
|
|
879
|
+
};
|
|
880
|
+
requestBody?: never;
|
|
881
|
+
responses: {
|
|
882
|
+
/** @description Default Response */
|
|
883
|
+
200: {
|
|
884
|
+
headers: {
|
|
885
|
+
[name: string]: unknown;
|
|
886
|
+
};
|
|
887
|
+
content: {
|
|
888
|
+
"application/json": {
|
|
889
|
+
data: {
|
|
890
|
+
paymentRequestId: string;
|
|
891
|
+
title: string;
|
|
892
|
+
description?: string;
|
|
893
|
+
amount?: number;
|
|
894
|
+
allowAmountOverride: boolean;
|
|
895
|
+
createdAt: string;
|
|
896
|
+
}[];
|
|
897
|
+
metadata?: {
|
|
898
|
+
/** @description Object containing the links to the related endpoints */
|
|
899
|
+
links?: {
|
|
900
|
+
self: {
|
|
901
|
+
/** @description URL pointing to the request itself */
|
|
902
|
+
href?: string;
|
|
903
|
+
};
|
|
904
|
+
next?: {
|
|
905
|
+
/** @description URL pointing to the next page of results in a paginated response. If there are no more results, this field may be omitted */
|
|
906
|
+
href?: string;
|
|
907
|
+
};
|
|
908
|
+
prev?: {
|
|
909
|
+
/** @description URL pointing to the previous page of results in a paginated response. If there are no more results, this field may be omitted */
|
|
910
|
+
href?: string;
|
|
911
|
+
};
|
|
912
|
+
first: {
|
|
913
|
+
/** @description URL pointing to the first page of results in a paginated response */
|
|
914
|
+
href?: string;
|
|
915
|
+
};
|
|
916
|
+
last: {
|
|
917
|
+
/** @description URL pointing to the first page of results in a paginated response */
|
|
918
|
+
href?: string;
|
|
919
|
+
};
|
|
920
|
+
/** @description It may contain a list of other useful URLs, e.g. one entry for page:'page 1', 'page 2' */
|
|
921
|
+
pages: {
|
|
922
|
+
[key: string]: {
|
|
923
|
+
href?: string;
|
|
924
|
+
};
|
|
925
|
+
};
|
|
926
|
+
};
|
|
927
|
+
/** @description Number representing the total number of available items */
|
|
928
|
+
totalCount?: number;
|
|
929
|
+
};
|
|
930
|
+
};
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
put?: never;
|
|
936
|
+
post?: never;
|
|
937
|
+
delete?: never;
|
|
938
|
+
options?: never;
|
|
939
|
+
head?: never;
|
|
940
|
+
patch?: never;
|
|
941
|
+
trace?: never;
|
|
942
|
+
};
|
|
880
943
|
"/api/v1/requests/{requestId}": {
|
|
881
944
|
parameters: {
|
|
882
945
|
query?: never;
|
|
@@ -10,8 +10,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
10
10
|
|
|
11
11
|
async getAddresses() {
|
|
12
12
|
return this.client.GET("/api/v1/addresses/").then(
|
|
13
|
-
(response) => formatResponse(response),
|
|
14
|
-
(reason) => formatError(reason),
|
|
13
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
14
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -21,8 +21,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
21
21
|
params: { path: { addressId } },
|
|
22
22
|
})
|
|
23
23
|
.then(
|
|
24
|
-
(response) => formatResponse(response),
|
|
25
|
-
(reason) => formatError(reason),
|
|
24
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
25
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -34,8 +34,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
34
34
|
body: data,
|
|
35
35
|
})
|
|
36
36
|
.then(
|
|
37
|
-
(response) => formatResponse(response),
|
|
38
|
-
(reason) => formatError(reason),
|
|
37
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
38
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -54,8 +54,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
54
54
|
body: data,
|
|
55
55
|
})
|
|
56
56
|
.then(
|
|
57
|
-
(response) => formatResponse(response),
|
|
58
|
-
(reason) => formatError(reason),
|
|
57
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
58
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -69,8 +69,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
69
69
|
body: data,
|
|
70
70
|
})
|
|
71
71
|
.then(
|
|
72
|
-
(response) => formatResponse(response),
|
|
73
|
-
(reason) => formatError(reason),
|
|
72
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
73
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -80,15 +80,15 @@ export class Profile extends BaseClient<paths> {
|
|
|
80
80
|
params: { path: { addressId } },
|
|
81
81
|
})
|
|
82
82
|
.then(
|
|
83
|
-
(response) => formatResponse(response),
|
|
84
|
-
(reason) => formatError(reason),
|
|
83
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
84
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
async getEntitlements() {
|
|
89
89
|
return this.client.GET("/api/v1/entitlements/").then(
|
|
90
|
-
(response) => formatResponse(response),
|
|
91
|
-
(reason) => formatError(reason),
|
|
90
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
91
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -98,8 +98,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
98
98
|
params: { path: { userId } },
|
|
99
99
|
})
|
|
100
100
|
.then(
|
|
101
|
-
(response) => formatResponse(response),
|
|
102
|
-
(reason) => formatError(reason),
|
|
101
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
102
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -111,8 +111,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
111
111
|
body: data,
|
|
112
112
|
})
|
|
113
113
|
.then(
|
|
114
|
-
(response) => formatResponse(response),
|
|
115
|
-
(reason) => formatError(reason),
|
|
114
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
115
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -126,8 +126,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
126
126
|
body: data,
|
|
127
127
|
})
|
|
128
128
|
.then(
|
|
129
|
-
(response) => formatResponse(response),
|
|
130
|
-
(reason) => formatError(reason),
|
|
129
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
130
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -146,8 +146,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
146
146
|
body: data,
|
|
147
147
|
})
|
|
148
148
|
.then(
|
|
149
|
-
(response) => formatResponse(response),
|
|
150
|
-
(reason) => formatError(reason),
|
|
149
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
150
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -161,8 +161,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
161
161
|
},
|
|
162
162
|
})
|
|
163
163
|
.then(
|
|
164
|
-
(response) => formatResponse(response),
|
|
165
|
-
(reason) => formatError(reason),
|
|
164
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
165
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -174,8 +174,8 @@ export class Profile extends BaseClient<paths> {
|
|
|
174
174
|
body: { ids },
|
|
175
175
|
})
|
|
176
176
|
.then(
|
|
177
|
-
(response) => formatResponse(response),
|
|
178
|
-
(reason) => formatError(reason),
|
|
177
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
178
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -20,8 +20,8 @@ export class Scheduler extends BaseClient<paths> {
|
|
|
20
20
|
body: tasks,
|
|
21
21
|
})
|
|
22
22
|
.then(
|
|
23
|
-
(response) => formatResponse(response),
|
|
24
|
-
(reason) => formatError(reason),
|
|
23
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
24
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -25,8 +25,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
25
25
|
},
|
|
26
26
|
})
|
|
27
27
|
.then(
|
|
28
|
-
(response) => formatResponse(response),
|
|
29
|
-
(reason) => formatError(reason),
|
|
28
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
29
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -63,8 +63,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
63
63
|
params: { query: { userId, organizationId } },
|
|
64
64
|
})
|
|
65
65
|
.then(
|
|
66
|
-
(response) => formatResponse(response),
|
|
67
|
-
(reason) => formatError(reason),
|
|
66
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
67
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -74,8 +74,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
74
74
|
params: { path: { id, organizationId } },
|
|
75
75
|
})
|
|
76
76
|
.then(
|
|
77
|
-
(response) => formatResponse(response),
|
|
78
|
-
(reason) => formatError(reason),
|
|
77
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
78
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -85,8 +85,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
85
85
|
body: { fileId: id },
|
|
86
86
|
})
|
|
87
87
|
.then(
|
|
88
|
-
(response) => formatResponse(response),
|
|
89
|
-
(reason) => formatError(reason),
|
|
88
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
89
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -100,8 +100,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
100
100
|
},
|
|
101
101
|
})
|
|
102
102
|
.then(
|
|
103
|
-
(response) => formatResponse(response),
|
|
104
|
-
(reason) => formatError(reason),
|
|
103
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
104
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -111,8 +111,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
111
111
|
body: { fileId, userId },
|
|
112
112
|
})
|
|
113
113
|
.then(
|
|
114
|
-
(response) => formatResponse(response),
|
|
115
|
-
(reason) => formatError(reason),
|
|
114
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
115
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -122,8 +122,8 @@ export class Upload extends BaseClient<paths> {
|
|
|
122
122
|
body: { fileId, userId },
|
|
123
123
|
})
|
|
124
124
|
.then(
|
|
125
|
-
(response) => formatResponse(response),
|
|
126
|
-
(reason) => formatError(reason),
|
|
125
|
+
(response) => formatResponse(response, this.serviceName, this.logger),
|
|
126
|
+
(reason) => formatError(reason, this.serviceName, this.logger),
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ResponseContent,
|
|
7
7
|
ResponseObjectMap,
|
|
8
8
|
} from "openapi-typescript-helpers";
|
|
9
|
+
import type { Logger } from "../../types/index.js";
|
|
9
10
|
|
|
10
11
|
export interface PaginationParams {
|
|
11
12
|
offset?: string | number;
|
|
@@ -52,12 +53,18 @@ export function preparePaginationParams(paginationParams?: PaginationParams): {
|
|
|
52
53
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
53
54
|
export function formatResponse<G extends Record<string | number, any>, O>(
|
|
54
55
|
response: FetchResponse<G, O, "application/json">,
|
|
56
|
+
serviceName: string,
|
|
57
|
+
logger?: Logger,
|
|
55
58
|
): DataResponseValue<G, O> {
|
|
56
59
|
let outputData = undefined;
|
|
57
60
|
let outputMetadata = undefined;
|
|
61
|
+
|
|
58
62
|
if (!response) {
|
|
63
|
+
logger?.debug(`${serviceName} - Undefined response`);
|
|
59
64
|
return {} as DataResponseValue<G, O>;
|
|
60
65
|
}
|
|
66
|
+
|
|
67
|
+
logger?.debug({ rawResponse: response }, `${serviceName} - Raw response`);
|
|
61
68
|
if (response.data) {
|
|
62
69
|
const dataEntries = Object.entries(response.data);
|
|
63
70
|
// by docs the body should contain a "data"
|
|
@@ -71,13 +78,24 @@ export function formatResponse<G extends Record<string | number, any>, O>(
|
|
|
71
78
|
outputData = containsData ? containsData[1] : response.data;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
const formattedResponse = {
|
|
75
82
|
data: outputData,
|
|
76
83
|
metadata: outputMetadata,
|
|
77
84
|
error: response.error,
|
|
78
85
|
} as unknown as DataResponseValue<G, O>;
|
|
86
|
+
|
|
87
|
+
logger?.debug({ formattedResponse }, `${serviceName} - Formatted response`);
|
|
88
|
+
|
|
89
|
+
return formattedResponse;
|
|
79
90
|
}
|
|
80
91
|
|
|
81
|
-
export function formatError<G, O>(
|
|
92
|
+
export function formatError<G, O>(
|
|
93
|
+
reason: unknown,
|
|
94
|
+
serviceName: string,
|
|
95
|
+
logger?: Logger,
|
|
96
|
+
): DataResponseValue<G, O> {
|
|
97
|
+
if (logger) {
|
|
98
|
+
logger.debug({ reason }, `${serviceName} - Got error`);
|
|
99
|
+
}
|
|
82
100
|
return { error: reason } as unknown as DataResponseValue<G, O>;
|
|
83
101
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { Analytics } from "@ogcio/analytics-sdk";
|
|
2
2
|
import { FeatureFlags } from "./client/clients/featureFlags/index.js";
|
|
3
3
|
|
|
4
|
+
import { Journey } from "./client/clients/journey/index.js";
|
|
4
5
|
import { Messaging } from "./client/clients/messaging/index.js";
|
|
5
6
|
import { Payments } from "./client/clients/payments/index.js";
|
|
6
7
|
import { Profile } from "./client/clients/profile/index.js";
|
|
7
8
|
import { Scheduler } from "./client/clients/scheduler/index.js";
|
|
8
9
|
import { Upload } from "./client/clients/upload/index.js";
|
|
9
|
-
import { Journey } from "./client/clients/journey/index.js";
|
|
10
10
|
export { getM2MTokenFn } from "./client/auth/index.js";
|
|
11
11
|
|
|
12
12
|
import type {
|
|
13
13
|
BuildingBlockSDKParams,
|
|
14
14
|
BuildingBlocksSDK,
|
|
15
|
+
Logger,
|
|
15
16
|
Services,
|
|
16
17
|
TokenFunction,
|
|
17
18
|
} from "./types/index.js";
|
|
18
19
|
|
|
20
|
+
export type { TokenFunction, BuildingBlocksSDK } from "./types/index.js";
|
|
21
|
+
|
|
19
22
|
// Create type that only includes services that are defined in params
|
|
20
|
-
type DefinedServices<T extends BuildingBlockSDKParams> = {
|
|
23
|
+
export type DefinedServices<T extends BuildingBlockSDKParams> = {
|
|
21
24
|
[K in keyof BuildingBlocksSDK as K extends keyof T["services"]
|
|
22
25
|
? T["services"][K] extends undefined
|
|
23
26
|
? never
|
|
@@ -27,33 +30,35 @@ type DefinedServices<T extends BuildingBlockSDKParams> = {
|
|
|
27
30
|
|
|
28
31
|
const createService = <K extends keyof Services>(
|
|
29
32
|
ServiceClass: new (
|
|
30
|
-
config: Services[K] & { getTokenFn: TokenFunction },
|
|
33
|
+
config: Services[K] & { getTokenFn: TokenFunction; logger?: Logger },
|
|
31
34
|
) => BuildingBlocksSDK[K],
|
|
32
35
|
config: Services[K] | undefined,
|
|
33
36
|
getTokenFn: TokenFunction,
|
|
37
|
+
logger?: Logger,
|
|
34
38
|
): BuildingBlocksSDK[K] | undefined => {
|
|
35
39
|
if (!config) return undefined;
|
|
36
|
-
return new ServiceClass({ ...config, getTokenFn });
|
|
40
|
+
return new ServiceClass({ ...config, getTokenFn, logger });
|
|
37
41
|
};
|
|
38
42
|
|
|
39
43
|
export const getBuildingBlockSDK = <T extends BuildingBlockSDKParams>(
|
|
40
44
|
params: T,
|
|
41
45
|
): DefinedServices<T> => {
|
|
42
|
-
const { services, getTokenFn } = params;
|
|
46
|
+
const { services, getTokenFn, logger } = params;
|
|
43
47
|
|
|
44
48
|
const sdk = {
|
|
45
|
-
analytics: createService(Analytics, services.analytics, getTokenFn),
|
|
46
|
-
messaging: createService(Messaging, services.messaging, getTokenFn),
|
|
47
|
-
payments: createService(Payments, services.payments, getTokenFn),
|
|
48
|
-
profile: createService(Profile, services.profile, getTokenFn),
|
|
49
|
-
scheduler: createService(Scheduler, services.scheduler, getTokenFn),
|
|
50
|
-
upload: createService(Upload, services.upload, getTokenFn),
|
|
49
|
+
analytics: createService(Analytics, services.analytics, getTokenFn, logger),
|
|
50
|
+
messaging: createService(Messaging, services.messaging, getTokenFn, logger),
|
|
51
|
+
payments: createService(Payments, services.payments, getTokenFn, logger),
|
|
52
|
+
profile: createService(Profile, services.profile, getTokenFn, logger),
|
|
53
|
+
scheduler: createService(Scheduler, services.scheduler, getTokenFn, logger),
|
|
54
|
+
upload: createService(Upload, services.upload, getTokenFn, logger),
|
|
51
55
|
featureFlags: createService(
|
|
52
56
|
FeatureFlags,
|
|
53
57
|
services.featureFlags,
|
|
54
58
|
getTokenFn,
|
|
59
|
+
logger,
|
|
55
60
|
),
|
|
56
|
-
journey: createService(Journey, services.journey, getTokenFn),
|
|
61
|
+
journey: createService(Journey, services.journey, getTokenFn, logger),
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
// Remove undefined services
|
package/src/types/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Analytics, AnalyticsOptions } from "@ogcio/analytics-sdk";
|
|
2
2
|
|
|
3
3
|
import type { FeatureFlags } from "../client/clients/featureFlags/index.js";
|
|
4
|
+
import type { Journey } from "../client/clients/journey/index.js";
|
|
4
5
|
import type { Messaging } from "../client/clients/messaging/index.js";
|
|
5
6
|
import type { Payments } from "../client/clients/payments/index.js";
|
|
6
7
|
import type { Profile } from "../client/clients/profile/index.js";
|
|
7
8
|
import type { Scheduler } from "../client/clients/scheduler/index.js";
|
|
8
9
|
import type { Upload } from "../client/clients/upload/index.js";
|
|
9
|
-
import type { Journey } from "../client/clients/journey/index.js";
|
|
10
10
|
|
|
11
11
|
const ANALYTICS = "analytics" as const;
|
|
12
12
|
const MESSAGING = "messaging" as const;
|
|
@@ -87,9 +87,26 @@ type M2MTokenFnConfig = {
|
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
interface LogFn {
|
|
91
|
+
<T extends object>(obj: T, msg?: string, ...args: unknown[]): void;
|
|
92
|
+
(obj: unknown, msg?: string, ...args: unknown[]): void;
|
|
93
|
+
(msg: string, ...args: unknown[]): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type Logger = {
|
|
97
|
+
fatal: LogFn;
|
|
98
|
+
error: LogFn;
|
|
99
|
+
warn: LogFn;
|
|
100
|
+
info: LogFn;
|
|
101
|
+
debug: LogFn;
|
|
102
|
+
trace: LogFn;
|
|
103
|
+
silent: LogFn;
|
|
104
|
+
};
|
|
105
|
+
|
|
90
106
|
interface BuildingBlockSDKParams {
|
|
91
107
|
services: Services;
|
|
92
108
|
getTokenFn: TokenFunction;
|
|
109
|
+
logger?: Logger;
|
|
93
110
|
}
|
|
94
111
|
|
|
95
112
|
interface BuildingBlocksSDK {
|