@pushwoosh/smart-components-kit 1.17.2 → 1.17.3

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,36 +1,32 @@
1
1
  import { type Message } from '@pushwoosh/rpc-v2-http-api-data/messages';
2
- export interface ResendEmailRequest {
3
- request: {
2
+ export type ResendEmailRequest = {
3
+ transaction_id: string;
4
+ segment: {
5
+ schedule: {
6
+ after: string;
7
+ };
8
+ expression: string;
4
9
  application: string;
5
- notifications: Array<{
6
- transactionId: string;
7
- preset?: string;
8
- campaign?: string;
9
- subject?: string;
10
- send_date: string;
11
- timezone?: string;
12
- devices_filter: string;
10
+ platforms: string[];
11
+ campaign?: string;
12
+ message_type: string;
13
+ email_payload: {
14
+ email_template?: string;
15
+ subject: {
16
+ default: string;
17
+ };
13
18
  from: {
14
19
  name: string;
15
20
  email: string;
16
21
  };
17
- 'reply-to'?: {
22
+ reply_to?: {
18
23
  name: string;
19
24
  email: string;
20
25
  };
21
- email_type: string;
22
26
  email_category?: string;
23
- use_auto_registration?: boolean;
24
- created_via?: string;
25
- capping_days?: number;
26
- capping_count?: number;
27
- capping_exclude?: boolean;
28
- capping_avoid?: boolean;
29
- send_rate?: number;
30
- send_rate_avoid?: boolean;
31
- }>;
27
+ };
32
28
  };
33
- }
29
+ };
34
30
  export declare class ResendEmailPayloadMapper {
35
31
  static getPayload(applicationCode: string, originalMessage: Message, newSubject: string): ResendEmailRequest;
36
32
  }
@@ -2,31 +2,33 @@ import { parseMessageProperties } from './helpers';
2
2
  export class ResendEmailPayloadMapper {
3
3
  static getPayload(applicationCode, originalMessage, newSubject) {
4
4
  const props = parseMessageProperties(originalMessage.properties);
5
- const devicesFilter = `((Event("${applicationCode}", "PW_EmailSent", date daysago lte 365, count eq 1, attribute "message_code" eq "${originalMessage.code}")) \\ (Event("${applicationCode}", "PW_EmailOpen", date daysago lte 365, count eq 1, attribute "message_code" eq "${originalMessage.code}")))`;
5
+ const expression = `((Event("${applicationCode}", "PW_EmailSent", date daysago lte 365, count eq 1, attribute "message_code" eq "${originalMessage.code}")) \\ (Event("${applicationCode}", "PW_EmailOpen", date daysago lte 365, count eq 1, attribute "message_code" eq "${originalMessage.code}")))`;
6
6
  return {
7
- request: {
7
+ transaction_id: crypto.randomUUID(),
8
+ segment: {
9
+ schedule: {
10
+ after: '0s'
11
+ },
12
+ expression,
8
13
  application: applicationCode,
9
- notifications: [{
10
- transactionId: crypto.randomUUID(),
11
- preset: props.preset,
12
- campaign: props.campaignCode,
13
- subject: newSubject,
14
- send_date: 'now',
15
- timezone: props.timezone,
16
- devices_filter: devicesFilter,
14
+ platforms: ['EMAIL'],
15
+ campaign: props.campaignCode,
16
+ message_type: props.email_type === 'transactional' ? 'MESSAGE_TYPE_TRANSACTIONAL' : 'MESSAGE_TYPE_MARKETING',
17
+ email_payload: {
18
+ email_template: props.preset,
19
+ subject: {
20
+ default: newSubject
21
+ },
17
22
  from: {
18
23
  name: props.email_from_name || '',
19
24
  email: props.email_from_email || ''
20
25
  },
21
- 'reply-to': props.email_reply_email ? {
26
+ reply_to: props.email_reply_email ? {
22
27
  name: props.email_reply_name || '',
23
28
  email: props.email_reply_email
24
29
  } : undefined,
25
- email_type: props.email_type || 'marketing',
26
- email_category: props.email_category,
27
- use_auto_registration: true,
28
- created_via: 'email cp'
29
- }]
30
+ email_category: props.email_category
31
+ }
30
32
  }
31
33
  };
32
34
  }
@@ -6,7 +6,7 @@ export const useResend = () => {
6
6
  const {
7
7
  httpClient,
8
8
  helpers: {
9
- getJsonApiUrl
9
+ getApiOrigin
10
10
  }
11
11
  } = useSPAContext();
12
12
  const {
@@ -15,17 +15,10 @@ export const useResend = () => {
15
15
  const resendEmail = useCallback(async (applicationCode, originalMessage, newSubject) => {
16
16
  const payload = ResendEmailPayloadMapper.getPayload(applicationCode, originalMessage, newSubject);
17
17
  try {
18
- const res = await httpClient.post(getJsonApiUrl('createEmailMessage'), {
19
- body: payload.request,
18
+ await httpClient.post(`${getApiOrigin('messaging-api')}/messaging/v2/notify`, {
19
+ body: payload,
20
20
  withAuthorization: true
21
21
  });
22
- if (res?.status_code !== 200) {
23
- openToast({
24
- title: res?.status_message || 'Failed to resend message',
25
- type: 'error'
26
- });
27
- return false;
28
- }
29
22
  openToast({
30
23
  title: 'Message resent successfully',
31
24
  type: 'success'
@@ -38,7 +31,7 @@ export const useResend = () => {
38
31
  });
39
32
  return false;
40
33
  }
41
- }, [httpClient, getJsonApiUrl, openToast]);
34
+ }, [httpClient, getApiOrigin, openToast]);
42
35
  return {
43
36
  resendEmail
44
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/smart-components-kit",
3
- "version": "1.17.2",
3
+ "version": "1.17.3",
4
4
  "description": "Stateful, data-connected React components shared by Pushwoosh micro-frontends",
5
5
  "repository": {
6
6
  "type": "git",