@dotbots-boutique/server-sdk 0.5.5 → 0.6.0

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.d.ts CHANGED
@@ -5,6 +5,8 @@ export declare class DotBotsBackend {
5
5
  private apiUrl;
6
6
  private environment;
7
7
  private proxyUrl;
8
+ private dotPlatformEventsUrl;
9
+ private dotPlatformEventsRaiserToken;
8
10
  constructor(config: DotBotsBackendConfig);
9
11
  initialize(): Promise<void>;
10
12
  ai(feature: string, request: BackendAiRequest, onDelta?: (delta: string) => void): Promise<AiResponse>;
@@ -18,6 +20,11 @@ export declare class DotBotsBackend {
18
20
  amount: bigint;
19
21
  }>;
20
22
  getUser(userId: string): Promise<DotBotsUser>;
23
+ raiseEvent(eventName: string, properties: Record<string, string>, options?: {
24
+ version?: string;
25
+ orgId?: string;
26
+ userId?: string;
27
+ }): Promise<void>;
21
28
  sendNotification(request: SendNotificationRequest): Promise<SendNotificationResponse>;
22
29
  private baseHeaders;
23
30
  private getProxyUrl;
package/dist/client.js CHANGED
@@ -8,6 +8,8 @@ class DotBotsBackend {
8
8
  apiUrl;
9
9
  environment;
10
10
  proxyUrl = null;
11
+ dotPlatformEventsUrl = null;
12
+ dotPlatformEventsRaiserToken = null;
11
13
  constructor(config) {
12
14
  this.appId = config.appId;
13
15
  this.appSecret = config.appSecret;
@@ -22,6 +24,10 @@ class DotBotsBackend {
22
24
  level: 'info',
23
25
  message: `[DotBotsBackend] Proxy URL from env: ${injectedProxyUrl}`,
24
26
  }));
27
+ }
28
+ this.dotPlatformEventsUrl = process.env.DOTPLATFORMEVENTS_URL ?? null;
29
+ this.dotPlatformEventsRaiserToken = process.env.DOTPLATFORMEVENTS_RAISER_TOKEN ?? null;
30
+ if (injectedProxyUrl) {
25
31
  return;
26
32
  }
27
33
  const response = await fetch(`${this.apiUrl}/api/proxy/config`, {
@@ -108,12 +114,37 @@ class DotBotsBackend {
108
114
  }
109
115
  return (await response.json());
110
116
  }
117
+ async raiseEvent(eventName, properties, options = {}) {
118
+ if (!this.dotPlatformEventsUrl || !this.dotPlatformEventsRaiserToken) {
119
+ throw new errors_1.DotBotsBackendError('EVENT_RAISER_NOT_CONFIGURED', 503);
120
+ }
121
+ const response = await fetch(`${this.dotPlatformEventsUrl}/api/events/raise`, {
122
+ method: 'POST',
123
+ headers: {
124
+ 'Content-Type': 'application/json',
125
+ 'X-Raiser-Token': this.dotPlatformEventsRaiserToken,
126
+ },
127
+ body: JSON.stringify({
128
+ eventName,
129
+ version: options.version ?? 'v1',
130
+ orgId: options.orgId,
131
+ userId: options.userId,
132
+ properties,
133
+ }),
134
+ signal: AbortSignal.timeout(10_000),
135
+ });
136
+ if (!response.ok) {
137
+ const body = (await response.json().catch(() => ({})));
138
+ throw new errors_1.DotBotsBackendError(body.error ?? 'EVENT_RAISE_FAILED', response.status);
139
+ }
140
+ }
111
141
  async sendNotification(request) {
112
142
  const url = 'https://dotnotifications-dotbots-api.apps.dotbots.boutique/api/send';
143
+ const { notificationAppSecret, ...rest } = request;
113
144
  const body = JSON.stringify({
114
- ...request,
145
+ ...rest,
115
146
  applicationExternalId: this.appId,
116
- appSecret: this.appSecret,
147
+ appSecret: notificationAppSecret,
117
148
  });
118
149
  console.log(JSON.stringify({
119
150
  level: 'info',
package/dist/types.d.ts CHANGED
@@ -68,6 +68,7 @@ export interface DotBotsUser {
68
68
  export interface SendNotificationRequest {
69
69
  userExternalId: string;
70
70
  userOrganisationExternalId: string;
71
+ notificationAppSecret: string;
71
72
  code?: string;
72
73
  notificationDescriptionId?: string;
73
74
  language?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotbots-boutique/server-sdk",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "DotBots Backend SDK — server-side AI calls, payments, and user lookups via the DotBots proxy",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",