@dotbots-boutique/server-sdk 0.5.1 → 0.5.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.
- package/dist/client.js +32 -6
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -109,16 +109,42 @@ class DotBotsBackend {
|
|
|
109
109
|
return (await response.json());
|
|
110
110
|
}
|
|
111
111
|
async sendNotification(request) {
|
|
112
|
-
const
|
|
112
|
+
const url = 'https://dotnotifications-dotbots-api.apps.dotbots.boutique/api/send';
|
|
113
|
+
const body = JSON.stringify(request);
|
|
114
|
+
console.log(JSON.stringify({
|
|
115
|
+
level: 'info',
|
|
116
|
+
message: `[DotBotsBackend] sendNotification → ${url}`,
|
|
117
|
+
code: request.code,
|
|
118
|
+
userExternalId: request.userExternalId,
|
|
119
|
+
userOrganisationExternalId: request.userOrganisationExternalId,
|
|
120
|
+
language: request.language,
|
|
121
|
+
important: request.important,
|
|
122
|
+
parameterKeys: request.parameters ? Object.keys(request.parameters) : [],
|
|
123
|
+
}));
|
|
124
|
+
const response = await fetch(url, {
|
|
113
125
|
method: 'POST',
|
|
114
|
-
headers:
|
|
115
|
-
body
|
|
126
|
+
headers: { 'Content-Type': 'application/json' },
|
|
127
|
+
body,
|
|
116
128
|
});
|
|
117
129
|
if (!response.ok) {
|
|
118
|
-
const
|
|
119
|
-
|
|
130
|
+
const responseBody = (await response.json().catch(() => ({})));
|
|
131
|
+
console.log(JSON.stringify({
|
|
132
|
+
level: 'error',
|
|
133
|
+
message: `[DotBotsBackend] sendNotification failed`,
|
|
134
|
+
status: response.status,
|
|
135
|
+
error: responseBody.error,
|
|
136
|
+
}));
|
|
137
|
+
throw new errors_1.DotBotsBackendError(responseBody.error ?? 'NOTIFICATION_FAILED', response.status);
|
|
120
138
|
}
|
|
121
|
-
|
|
139
|
+
const result = (await response.json());
|
|
140
|
+
console.log(JSON.stringify({
|
|
141
|
+
level: 'info',
|
|
142
|
+
message: `[DotBotsBackend] sendNotification OK`,
|
|
143
|
+
id: result.id,
|
|
144
|
+
type: result.type,
|
|
145
|
+
status: result.status,
|
|
146
|
+
}));
|
|
147
|
+
return result;
|
|
122
148
|
}
|
|
123
149
|
baseHeaders() {
|
|
124
150
|
return {
|
package/package.json
CHANGED