@dev.smartpricing/message-composer-layer 4.3.2-fix.1 → 4.5.1-automation.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/README.md +357 -46
- package/app/api/automations.ts +74 -0
- package/app/api/brands.ts +20 -13
- package/app/api/client.ts +15 -6
- package/app/api/compilation.ts +13 -3
- package/app/api/dynamicValues.ts +6 -2
- package/app/api/index.ts +1 -0
- package/app/api/media.ts +6 -3
- package/app/api/messageGroups.ts +34 -15
- package/app/api/meta.ts +62 -4
- package/app/api/organization.ts +10 -1
- package/app/api/tracking.ts +2 -2
- package/app/app.config.ts +10 -0
- package/app/components/Automations/ActionCard.vue +174 -0
- package/app/components/Automations/ActionEditor.vue +398 -0
- package/app/components/Automations/Actions.vue +158 -0
- package/app/components/Automations/CloneModal.vue +78 -0
- package/app/components/Automations/Conditions.vue +155 -0
- package/app/components/Automations/Create.vue +114 -0
- package/app/components/Automations/Data.vue +46 -0
- package/app/components/Automations/DeleteModal.vue +80 -0
- package/app/components/Automations/Edit.vue +145 -0
- package/app/components/Automations/Form.vue +282 -0
- package/app/components/Automations/List.vue +370 -0
- package/app/components/Automations/PageGate.vue +50 -0
- package/app/components/Automations/SaveProblems.vue +54 -0
- package/app/components/Automations/Unavailable.vue +71 -0
- package/app/components/Automations/UnavailableBadge.vue +35 -0
- package/app/components/Common/AppContextErrors.vue +30 -0
- package/app/components/Common/HtmlPreviewIframe.vue +17 -3
- package/app/components/Common/MessageGroupSelect.vue +193 -26
- package/app/components/Common/MessagePreviewSlideover.vue +3 -0
- package/app/components/Common/OrganizationGate.vue +51 -0
- package/app/components/Common/OrganizationSelect.vue +27 -0
- package/app/components/Common/WhatsappNotConfigured.vue +20 -0
- package/app/components/Composer/EmailComposer.vue +9 -1
- package/app/components/Composer/MessageLibrary.vue +25 -7
- package/app/components/Composer/WabaSelectModal.vue +73 -0
- package/app/components/Composer/WhatsappComposer.vue +83 -4
- package/app/components/Editor/RichTextEditor.vue +14 -2
- package/app/components/Filters/DateInput.vue +57 -0
- package/app/components/Filters/Editor.vue +163 -0
- package/app/components/Filters/Row.vue +119 -0
- package/app/components/Filters/Summary.vue +215 -0
- package/app/components/Filters/UnavailableRow.vue +74 -0
- package/app/components/Filters/ValueInput.vue +215 -0
- package/app/components/Layout/BasePage.vue +2 -0
- package/app/components/MessageSendFlow/EmailPreview.vue +81 -0
- package/app/components/MessageSendFlow/LanguageSelect.vue +39 -0
- package/app/components/MessageSendFlow/MessageSendFlow.vue +265 -0
- package/app/components/MessageSendFlow/ParametersForm.vue +51 -0
- package/app/components/MetaImport/Button.vue +50 -0
- package/app/components/MetaImport/Dialog.vue +261 -0
- package/app/components/MetaImport/Outcome.vue +136 -0
- package/app/components/MetaImport/ProposalList.vue +192 -0
- package/app/components/TemplateList/BaseTable.vue +177 -108
- package/app/components/Whatsapp/Preview.vue +17 -16
- package/app/components/Whatsapp/PreviewPanel.vue +7 -1
- package/app/components/Whatsapp/Translator/Header.vue +4 -19
- package/app/composables/apiErrorMessages.ts +1 -0
- package/app/composables/automationsContext.ts +42 -0
- package/app/composables/composerContext.ts +9 -7
- package/app/composables/useAutomationClone.ts +33 -0
- package/app/composables/useAutomationEditorTrip.ts +77 -0
- package/app/composables/useAutomationSaveProblems.ts +82 -0
- package/app/composables/useAutomationUnavailable.ts +98 -0
- package/app/composables/useAutomationsGate.ts +68 -0
- package/app/composables/useBuiltInOptionLists.ts +44 -0
- package/app/composables/useEditorTripBack.ts +15 -0
- package/app/composables/useEffectiveOrganization.ts +34 -0
- package/app/composables/useMessageGroupList.ts +186 -0
- package/app/composables/useMessageGroupWaba.ts +76 -0
- package/app/composables/useMessageSendFlow.ts +284 -0
- package/app/composables/usePagedMessageGroups.ts +78 -0
- package/app/composables/useTemplateOperations.ts +31 -7
- package/app/composables/useTracking.ts +14 -5
- package/app/composables/useWhatsappConfiguration.ts +32 -0
- package/app/layouts/default.vue +5 -1
- package/app/middleware/automations-enabled.ts +12 -0
- package/app/pages/automations/[id].vue +87 -0
- package/app/pages/automations/index.vue +28 -0
- package/app/pages/automations/new.vue +53 -0
- package/app/pages/brands.vue +1 -0
- package/app/pages/images.vue +4 -0
- package/app/pages/index.vue +6 -1
- package/app/pages/preview/[id].vue +2 -0
- package/app/pages/template/email/[id].vue +5 -0
- package/app/pages/template/email/create.vue +5 -0
- package/app/pages/template/whatsapp/[id].vue +6 -0
- package/app/pages/template/whatsapp/create.vue +5 -0
- package/app/queries/automations.ts +206 -0
- package/app/queries/brands.ts +27 -7
- package/app/queries/compilation.ts +16 -3
- package/app/queries/dynamicValues.ts +19 -2
- package/app/queries/index.ts +1 -0
- package/app/queries/media.ts +8 -3
- package/app/queries/messageGroups.ts +84 -36
- package/app/queries/meta.ts +100 -5
- package/app/stores/appContext.ts +18 -48
- package/app/stores/editorTrip.ts +67 -0
- package/app/stores/effectiveOrganization.ts +128 -0
- package/app/stores/emailEditor.ts +5 -1
- package/app/stores/metaSubmission.ts +7 -17
- package/app/types/app-config.d.ts +3 -0
- package/app/types/tracking.ts +50 -0
- package/app/utils/automations/form.ts +389 -0
- package/app/utils/automations/metadata.ts +71 -0
- package/app/utils/automations/unavailable.ts +90 -0
- package/app/utils/filters/data/countries.json +998 -0
- package/app/utils/filters/data/languages.json +754 -0
- package/app/utils/filters/rows.ts +367 -0
- package/app/utils/testIds.const.ts +137 -0
- package/i18n/locales/de.ts +419 -2
- package/i18n/locales/en.ts +398 -2
- package/i18n/locales/es.ts +403 -2
- package/i18n/locales/fr.ts +410 -2
- package/i18n/locales/it.ts +409 -2
- package/package.json +4 -4
- package/app.config.ts +0 -5
package/README.md
CHANGED
|
@@ -1,75 +1,386 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dev.smartpricing/message-composer-layer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Message Composer as a [Nuxt layer](https://nuxt.com/docs/getting-started/layers). A host app extends it and gets the composer pages (message library, editor, preview, brands, images) plus embeddable components such as the **Message Send Flow**.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The layer is published on the private Smartpricing npm registry together with `@dev.smartpricing/message-composer-utils` (shared types, helpers and Zod schemas, subpath exports `/types`, `/utils` and `/schemas`). Both packages share one version number.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Host setup
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
1. Install the layer and its peer:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @dev.smartpricing/message-composer-layer
|
|
13
|
+
pnpm add -D nuxt-ui-layer@github:smartpricing/smartness-nuxt-ui#v1.14.4 # peer, >= 1.3.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`nuxt-ui-layer` is extended by `@dev.smartpricing/platform-layer`, which this layer extends, so the host does not list it in `extends`.
|
|
17
|
+
|
|
18
|
+
2. Extend it and set the API keys. `BACKEND_BASE_URL`, `PLATFORM_URL` and `CSRF_COOKIE_NAME` are declared by `@dev.smartpricing/platform-layer`, which this layer extends; set them once for both.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// nuxt.config.ts
|
|
22
|
+
export default defineNuxtConfig({
|
|
23
|
+
extends: ['@dev.smartpricing/message-composer-layer'],
|
|
24
|
+
runtimeConfig: {
|
|
25
|
+
public: {
|
|
26
|
+
COMPOSER_API_URL: '', // NUXT_PUBLIC_COMPOSER_API_URL
|
|
27
|
+
BACKEND_BASE_URL: '', // NUXT_PUBLIC_BACKEND_BASE_URL
|
|
28
|
+
PLATFORM_URL: '', // NUXT_PUBLIC_PLATFORM_URL
|
|
29
|
+
CSRF_COOKIE_NAME: '', // NUXT_PUBLIC_CSRF_COOKIE_NAME: smt_csrf | smt_csrf_stage | smt_csrf_dev
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Provide the composer context before any layer component renders (`app.vue` or a plugin). `product` is required; everything else has a default.
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
defineComposerContext({
|
|
40
|
+
product: ref('chat'), // 'connect' | 'chat' | 'pms' | 'pricing'
|
|
41
|
+
channels: ref(['whatsapp']),
|
|
42
|
+
mainLanguage: ref('it'),
|
|
43
|
+
// organization_id: useAuth().organizationId, // only when the Host works on one Organization
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
useNuxtApp().hook('composer:auth-error', () => {
|
|
47
|
+
// 401 from the composer API: the session is gone, decide what to do
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Auth is cookie-based through platform-layer. The full `ComposerContext` interface lives in `app/composables/composerContext.ts`; the design and the parent/layer contract are in [`docs/nuxt-layer-design.md`](../../docs/nuxt-layer-design.md).
|
|
53
|
+
|
|
54
|
+
See "Organization and WABA" below for what `organization_id` and `metaWabaId` do.
|
|
55
|
+
|
|
56
|
+
4. Tracking is opt-in: set `composer.tracking: true` in the host's `app.config.ts` to have the layer post its events to `POST /tracking/event`.
|
|
12
57
|
|
|
13
|
-
|
|
14
|
-
pnpm install
|
|
58
|
+
The layer's pages are mounted at root (`/`, `/template/...`, `/preview/...`, `/brands`, `/images`). Remap them with `pages:extend` if the host already owns those routes. The Automation pages (`/automations/...`) are mounted too and answer 404 until the Host turns them on: see "Automation pages" below.
|
|
15
59
|
|
|
16
|
-
|
|
17
|
-
yarn install
|
|
60
|
+
## Organization and WABA
|
|
18
61
|
|
|
19
|
-
|
|
20
|
-
|
|
62
|
+
No request depends on an ambient Organization: every request names the one it is for (ADR [0014](../../docs/adr/0014-organization-explicit-on-every-request.md)). The Host no longer has to know it.
|
|
63
|
+
|
|
64
|
+
**Organization.** `organization_id` is optional in the context.
|
|
65
|
+
|
|
66
|
+
- **Given**: the layer works on that Organization and shows no selector. Passing the key is what counts, not its value: it may arrive late (a ref filled after the first render), and until then the layer waits (`status` is `resolving`) and sends no resource request, so a Host does not need to hold the composer back until its Tenant is loaded. A Host that passes the key and never fills it leaves the composer waiting.
|
|
67
|
+
- **Omitted** (the key is not passed at all): the layer asks the backend which Organizations the user can reach (`GET /organizations`). With one, it uses it and looks as before. With several, the Message Group, Brands and images pages show an **Organization selector** in their header: it filters what is listed and decides where new resources are created. The choice is remembered in the browser's local storage and checked against the reachable list on load. There is no "all Organizations" view.
|
|
68
|
+
|
|
69
|
+
On an editor or preview page the Organization is always the one of the Message Group on screen, whatever the selector says, so a link to a Message Group of any Organization the user can reach works.
|
|
70
|
+
|
|
71
|
+
**Effective Organization.** `useEffectiveOrganization()` (auto-imported) is the Host's read-only view of the Organization the layer is working on: `organizationId` (`null` until resolved) and `status` (`resolving` | `resolved` | `failed` | `none`). Use it for anything the Host supplies per Organization, such as `organizationData` (the test-email sender addresses and accommodation name):
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const organizationData = ref<OrganizationData>({ senderEmails: [] })
|
|
75
|
+
defineComposerContext({ product: ref('chat'), organizationData })
|
|
76
|
+
|
|
77
|
+
// After `defineComposerContext()`: the composable reads the context.
|
|
78
|
+
const { organizationId } = useEffectiveOrganization()
|
|
79
|
+
watch(
|
|
80
|
+
organizationId,
|
|
81
|
+
async (id) => {
|
|
82
|
+
organizationData.value = id ? await loadSenders(id) : { senderEmails: [] }
|
|
83
|
+
},
|
|
84
|
+
{ immediate: true },
|
|
85
|
+
)
|
|
21
86
|
```
|
|
22
87
|
|
|
23
|
-
|
|
88
|
+
**WABA.** The Host does not have to supply the WABA: the WABAs follow the Organization and the backend resolves them (ADR [0015](../../docs/adr/0015-message-group-waba-fixed-at-first-submission.md)). WhatsApp is configured when the Host's `channels` include `whatsapp` and the Organization has at least one WABA. A Message Group is submitted to one WABA, chosen at its first submission and fixed from then on; with several WABAs it is the `metaWabaId` the Host passed, when that is one of them, and otherwise the user picks one when requesting approval. `metaWabaId` in the context is optional.
|
|
24
89
|
|
|
25
|
-
|
|
90
|
+
### Upgrading to 4.5.0
|
|
26
91
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
92
|
+
Nothing is required: a Host that keeps passing `organization_id` and `metaWabaId` behaves as before.
|
|
93
|
+
|
|
94
|
+
- **Removed** from `ComposerContext` and from `AppContextConfig` in utils (no code read them): `authenticationToken`, `strategy`, `metaAccessToken`, `dinamicValues`. Remove them from the `defineComposerContext()` call. The utils types `AppContextState` and `ContextSource` are gone too.
|
|
95
|
+
- **Changed**: `metaWabaId` no longer decides where a WhatsApp submission goes and is no longer required for the WhatsApp channel; with several WABAs on the Organization it names the one a new Message Group is submitted to, and the user is asked only without it.
|
|
96
|
+
- **Deprecated**, removed in 5.0.0: the `sm-organization-id` and `x-meta-waba-id` request headers. The layer no longer sends them; the backend still accepts them from Hosts on an older layer.
|
|
97
|
+
- **New**: `organization_id` is optional, the Organization selector, `useEffectiveOrganization()`, and the `organizationId` and `wabaId` props of the Message Send Flow.
|
|
98
|
+
|
|
99
|
+
## Message Send Flow
|
|
100
|
+
|
|
101
|
+
`MessageSendFlow` walks an operator from "which Message" to "here is what to send", in two steps inside a container the host owns (Smartchat: a modal):
|
|
102
|
+
|
|
103
|
+
1. **Message**: pick a **Sendable** Message Group (at least one approved Message; groups with none are greyed out with a reason) and one of its approved languages.
|
|
104
|
+
2. **Parameters**: one required input per operator parameter of the chosen Message, prefilled from the host, editable. `brand_*` keys are hidden and filled server-side. **Confirm** calls `POST /message-groups/:id/compile` once (`strict: true`, `strict_language: true`) and emits the **Sendable Message** the backend built.
|
|
30
105
|
|
|
31
|
-
|
|
32
|
-
pnpm dev
|
|
106
|
+
The preview follows every step in a right panel: the picked Message as the guest receives it (the WhatsApp bubble for `whatsapp_v1`, the compiled email for `email_v1`), with the typed values substituted live. Plan a container at least ~1100 px wide (Nuxt UI `max-w-6xl`); the panel is 400 px, the stepper 200 px.
|
|
33
107
|
|
|
34
|
-
|
|
35
|
-
yarn dev
|
|
108
|
+
Back and Next move between steps, Cancel is always available, Confirm only on Parameters. The action bar renders under the steps, or wherever `actionsTo` points (a modal footer). The component has no outer padding: the host's container pads it. The component owns no overlay and no send, and it keeps its state after `compiled`: closing the container is the host's decision. There is no reset API; remount it (`:key`) to start over.
|
|
36
109
|
|
|
37
|
-
|
|
38
|
-
|
|
110
|
+
The flow works on one Organization and never shows a selector: the `organizationId` prop when the Host gives one (Smartchat: the conversation's), otherwise the one the layer resolved, which is also the one the page's selector is on. With `organizationId` the flow lists and compiles that Organization's Sendable Message Groups whatever the rest of the page is working on. With `wabaId` it offers only the WhatsApp Message Groups on the WABA the Host sends from.
|
|
111
|
+
|
|
112
|
+
The `/compile` contract (request, response with `message`, error codes) is documented in [`docs/compile-and-send.md`](../../docs/compile-and-send.md).
|
|
113
|
+
|
|
114
|
+
### Mount
|
|
115
|
+
|
|
116
|
+
```vue
|
|
117
|
+
<script setup lang="ts">
|
|
118
|
+
import type { SendableMessage } from '@dev.smartpricing/message-composer-utils/types'
|
|
119
|
+
|
|
120
|
+
const open = ref(true)
|
|
121
|
+
const groupId = ref<string>() // optional preselect, read back after a pick
|
|
122
|
+
|
|
123
|
+
function onCompiled(message: SendableMessage) {
|
|
124
|
+
open.value = false
|
|
125
|
+
// hand `message` to your send pipeline, see "Smartchat glue" below
|
|
126
|
+
}
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<template>
|
|
130
|
+
<UModal v-model:open="open" title="New WhatsApp conversation">
|
|
131
|
+
<template #body>
|
|
132
|
+
<MessageSendFlow
|
|
133
|
+
v-model:message-group-id="groupId"
|
|
134
|
+
:organization-id="conversation.organizationId"
|
|
135
|
+
:waba-id="conversation.wabaId"
|
|
136
|
+
language="it"
|
|
137
|
+
:parameters="{ guest_name: 'Mario', guest_fullname: 'Mario Rossi' }"
|
|
138
|
+
actions-to="#send-flow-actions"
|
|
139
|
+
@compiled="onCompiled"
|
|
140
|
+
@cancel="open = false"
|
|
141
|
+
@error="(e) => console.warn(e.code, e.details)"
|
|
142
|
+
/>
|
|
143
|
+
</template>
|
|
144
|
+
<template #footer>
|
|
145
|
+
<!-- Cancel, Back, Next and Confirm render here -->
|
|
146
|
+
<div id="send-flow-actions" class="w-full" />
|
|
147
|
+
</template>
|
|
148
|
+
</UModal>
|
|
149
|
+
</template>
|
|
39
150
|
```
|
|
40
151
|
|
|
41
|
-
|
|
152
|
+
### Props
|
|
42
153
|
|
|
43
|
-
|
|
154
|
+
| Prop | Type | Default | Description |
|
|
155
|
+
| ---------------- | ------------------------ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
156
|
+
| `messageGroupId` | `string` (`v-model`) | `undefined` | Two-way: preselect a group, read back what the operator picked. A preselected group that is not Sendable raises `NOT_SENDABLE` and leaves the picker usable. |
|
|
157
|
+
| `renderType` | `RenderType` | `'whatsapp_v1'` | Channel of the Messages offered: `whatsapp_v1` or `email_v1`. Picker, languages, parameters, preview and the Sendable Message follow it. |
|
|
158
|
+
| `language` | `string` | `undefined` | Preferred language (see the language rule). |
|
|
159
|
+
| `parameters` | `Record<string, string>` | `undefined` | Editable prefill of the parameter inputs. Keys the chosen Message does not need are ignored. |
|
|
160
|
+
| `brandId` | `string` | `undefined` | Brand override forwarded to `/compile` as `brand_id`; defaults to the group's brand. |
|
|
161
|
+
| `organizationId` | `string` | `undefined` | The Organization the flow works on. Unset, the one the layer resolved. A preselected group of another Organization raises `NOT_OFFERED`. |
|
|
162
|
+
| `wabaId` | `string` | `undefined` | The WABA the Host sends from: with `whatsapp_v1`, only Message Groups on it are offered. Unset, the groups of every WABA. Ignored for `email_v1`. |
|
|
163
|
+
| `actionsTo` | `string \| HTMLElement` | `undefined` | Where the Cancel/Back/Next/Confirm bar renders, e.g. a `UModal` footer element. Unset, it renders under the steps. |
|
|
44
164
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
165
|
+
### Emits
|
|
166
|
+
|
|
167
|
+
| Event | Payload | When |
|
|
168
|
+
| ---------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
169
|
+
| `compiled` | `SendableMessage` | Confirm succeeded. The Sendable Message is the `message` field of the `/compile` response, untouched: `WhatsappSendableMessage` for `whatsapp_v1`, `EmailSendableMessage` for `email_v1`. |
|
|
170
|
+
| `cancel` | none | The operator pressed Cancel (on any step). |
|
|
171
|
+
| `error` | `{ code: MessageSendFlowErrorCode, message: string, details?: unknown }` | Every failure the inline alert shows, so the host can log or surface it. `message` is the layer's translated text, the same string the alert shows. |
|
|
172
|
+
|
|
173
|
+
Types: `SendableMessage` from `@dev.smartpricing/message-composer-utils/types`; `MessageSendFlowError`, `MessageSendFlowErrorCode` and `MessageSendFlowEmits` from the layer's `app/composables/useMessageSendFlow.ts`.
|
|
174
|
+
|
|
175
|
+
### Error codes
|
|
176
|
+
|
|
177
|
+
| Code | Raised by | Meaning | `details` |
|
|
178
|
+
| ------------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
179
|
+
| `NOT_SENDABLE` | layer | The preselected or picked group has no approved Message. The picker stays usable; the alert clears once a Sendable group is picked. | none |
|
|
180
|
+
| `NOT_OFFERED` | layer | The preselected group belongs to another Organization than `organizationId`, or is not on `wabaId`. The picker stays usable. | none |
|
|
181
|
+
| `MISSING_PARAMETERS` | layer | Confirm pressed with an empty required parameter (checked client-side before calling `/compile`). | `{ missing: string[] }` |
|
|
182
|
+
| `MISSING_PARAMETERS` | backend | `/compile` reported a required key as absent. | the backend error body |
|
|
183
|
+
| `TEMPLATE_NOT_SUBMITTED` | backend | The WhatsApp template was never submitted to Meta. | the backend error body |
|
|
184
|
+
| `TEMPLATE_NOT_APPROVED` | backend | The Message is not approved by Meta. | the backend error body |
|
|
185
|
+
| `COMPILE_FAILED` | layer | Any other `/compile` failure, or a response without `message`. | the backend body or the error |
|
|
186
|
+
|
|
187
|
+
A 401 is not an `error` emit: it reaches the host through the `composer:auth-error` Nuxt hook like everywhere else in the layer.
|
|
188
|
+
|
|
189
|
+
### Language rule
|
|
190
|
+
|
|
191
|
+
The language selected in step 1 is the `language` prop when that Message is approved, otherwise the first approved Message in the group's `messages[]` order. It is recomputed whenever the group or the `language` prop changes. Non-approved languages stay visible as disabled radio cards showing their status; only approved ones can be picked.
|
|
192
|
+
|
|
193
|
+
### Reused blocks and their new props
|
|
194
|
+
|
|
195
|
+
- `MessageGroupSelect` (auto-import `CommonMessageGroupSelect`) gained `eligibility?: 'active' | 'sendable'`. `active` (default, the composer's own picker) selects groups whose every Message is approved; `sendable` selects groups with at least one approved Message. The disabled tooltip and the "hide inactive" filter follow the mode. The send flow uses `sendable`. It also takes `organizationId` (list that Organization instead of the resolved one) and `wabaId` (with `renderType="whatsapp_v1"`, only the groups on that WABA). Details in [`docs/message-group-select-migration.md`](../../docs/message-group-select-migration.md).
|
|
196
|
+
- `WhatsappPreview` gained `parameters?: Record<string, string>`: non-empty values override the organization-level resolved values, keys not in the map keep the resolved mock, an empty string shows the raw `{{key}}` placeholder.
|
|
197
|
+
|
|
198
|
+
### Exported blocks
|
|
199
|
+
|
|
200
|
+
All of these are auto-imported in a host that extends the layer, so a different layout can be composed without forking:
|
|
201
|
+
|
|
202
|
+
| Auto-import name | File | Role |
|
|
203
|
+
| ------------------------------- | ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
204
|
+
| `MessageSendFlow` | `app/components/MessageSendFlow/MessageSendFlow.vue` | The composed two-step flow. |
|
|
205
|
+
| `MessageSendFlowLanguageSelect` | `app/components/MessageSendFlow/LanguageSelect.vue` | Radio cards of a group's languages; props `languages`, `v-model` code. |
|
|
206
|
+
| `MessageSendFlowParametersForm` | `app/components/MessageSendFlow/ParametersForm.vue` | One input per key; props `parameterKeys`, `placeholders`, `loading`, `v-model` values. |
|
|
207
|
+
| `CommonMessageGroupSelect` | `app/components/Common/MessageGroupSelect.vue` | The picker, with `eligibility="sendable"`. |
|
|
208
|
+
| `WhatsappPreview` | `app/components/Whatsapp/Preview.vue` | The bubble, with the `parameters` override. |
|
|
209
|
+
| `MessageSendFlowEmailPreview` | `app/components/MessageSendFlow/EmailPreview.vue` | The compiled email (subject, HTML) for the typed values; props `messageGroupId`, `language`, `parameters`, `brandId`. |
|
|
210
|
+
|
|
211
|
+
The data flow (group, language rule, parameters, one compile on Confirm, error mapping) is `useMessageSendFlow()` in `app/composables/useMessageSendFlow.ts`. Test ids for every control are in `messageSendFlowTestIds` (`app/utils/testIds.const.ts`).
|
|
212
|
+
|
|
213
|
+
### Smartchat glue
|
|
48
214
|
|
|
49
|
-
|
|
50
|
-
pnpm build
|
|
215
|
+
The emitted Sendable Message is the content object Smartchat already sends, so the glue is a two-field pick:
|
|
51
216
|
|
|
52
|
-
|
|
53
|
-
|
|
217
|
+
```ts
|
|
218
|
+
import type { SendableMessage } from '@dev.smartpricing/message-composer-utils/types'
|
|
54
219
|
|
|
55
|
-
|
|
56
|
-
|
|
220
|
+
function onCompiled(message: SendableMessage) {
|
|
221
|
+
sendMessage({
|
|
222
|
+
contentType: message.type, // 'WhatsappTemplateMessage' | 'HtmlMessage'
|
|
223
|
+
content: message,
|
|
224
|
+
language:
|
|
225
|
+
message.type === 'WhatsappTemplateMessage' ? message.meta.data.language.code : language,
|
|
226
|
+
})
|
|
227
|
+
}
|
|
57
228
|
```
|
|
58
229
|
|
|
59
|
-
|
|
230
|
+
For WhatsApp, `message.meta.data` is the Meta template object (`name`, `language`, `components` with the filled parameters) and `message.meta.template` is the raw translated template stored at submission, the one Smartchat renders in the bubble. For email, `message` is the `HtmlMessage` content compile-and-send publishes (`subject`, `text` and `rawHtml` both the compiled HTML, `skipTranslation: true`); it carries no language, so the host keeps the one the operator picked from its own state.
|
|
60
231
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
232
|
+
### Tracking
|
|
233
|
+
|
|
234
|
+
With tracking enabled the flow reports `send_flow.confirm` (`message_name`, `message_category`, `language`, `parameters_count`), `send_flow.cancel` (`step`: `message` | `parameters`) and `send_flow.error` (`code`).
|
|
235
|
+
|
|
236
|
+
### Dev harness
|
|
237
|
+
|
|
238
|
+
`apps/frontend` (this monorepo's standalone host) has a permanent `/debug/send-flow` page that plays the host: preselect, preferred language, prefill JSON, brand id, the flow's own Organization and WABA, inline or modal container, remount, and a log of every emit.
|
|
239
|
+
|
|
240
|
+
## Automation pages
|
|
241
|
+
|
|
242
|
+
Three pages list, create and edit the Automations of the Host's Product. The Automations live in the Automation Engine and the composer backend is the only way to them (ADR [0016](../../docs/adr/0016-automations-live-in-the-automation-engine.md)). The pages are off until a Host turns them on (ADR [0019](../../docs/adr/0019-automation-pages-off-until-a-host-turns-them-on.md)): an upgrade changes nothing for a Host that does not set the flag.
|
|
243
|
+
|
|
244
|
+
1. Turn them on in the Host's `app.config.ts`, next to `composer.tracking`:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
export default defineAppConfig({
|
|
248
|
+
composer: { automations: true },
|
|
249
|
+
})
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
The routes always exist. While the flag is off, a layer middleware on those pages answers 404. The flag is static: a Host that wants the pages for some Organizations only does it with its own guard.
|
|
253
|
+
|
|
254
|
+
2. Provide the Automations context before an Automation page renders (`app.vue` or a plugin), as `defineComposerContext()` and apart from it:
|
|
255
|
+
|
|
256
|
+
```vue
|
|
257
|
+
<script setup lang="ts">
|
|
258
|
+
const { countries, languages } = useBuiltInOptionLists()
|
|
259
|
+
const tags = ref<AutomationOption[]>([]) // fetched and kept current by the Host
|
|
260
|
+
|
|
261
|
+
defineAutomationsContext({
|
|
262
|
+
optionLists: computed(() => ({
|
|
263
|
+
countries: countries.value,
|
|
264
|
+
languages: languages.value,
|
|
265
|
+
tags: tags.value,
|
|
266
|
+
})),
|
|
267
|
+
currency: ref('EUR'),
|
|
268
|
+
})
|
|
269
|
+
</script>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Routes
|
|
273
|
+
|
|
274
|
+
| Route name | Path | Page |
|
|
275
|
+
| ------------------- | ------------------ | ------------------------------------------------------------------------------------- |
|
|
276
|
+
| `automations-list` | `/automations` | The Automations of the Host's Product. Clone and delete are actions here, not routes. |
|
|
277
|
+
| `automation-create` | `/automations/new` | A new Automation. |
|
|
278
|
+
| `automation-edit` | `/automations/:id` | An existing Automation; a clone opens here. |
|
|
279
|
+
|
|
280
|
+
Link to them by name. The paths are the Host's to remap in `pages:extend`, and the Automation pages may sit under a different prefix than the Message pages: every link between them and the Message editor is by route name.
|
|
281
|
+
|
|
282
|
+
### `defineAutomationsContext(context)`
|
|
283
|
+
|
|
284
|
+
`AutomationsContext` and `AutomationOption` live in `app/composables/automationsContext.ts`.
|
|
285
|
+
|
|
286
|
+
| Key | Type | Description |
|
|
287
|
+
| ------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
288
|
+
| `optionLists` | `Ref<Record<string, AutomationOption[]>>` | Required. The option lists, by the name the Automation Catalog gives them (the `option_list` of a Condition Field). An `AutomationOption` is `{ value: string \| number, label: string }`, label already translated. A list that is not there shows as empty. |
|
|
289
|
+
| `currency` | `Ref<string \| undefined>` | Optional. ISO code of the currency `price` fields show; EUR when absent. Never a conversion. |
|
|
290
|
+
|
|
291
|
+
The Automation Catalog holds no option: every list is the Host's (ADR [0017](../../docs/adr/0017-automation-catalog-served-by-the-backend.md)). There are no loader callbacks: the Host fetches the lists and keeps the refs current. Countries and languages can come from `useBuiltInOptionLists()`.
|
|
292
|
+
|
|
293
|
+
### What a page needs to work
|
|
294
|
+
|
|
295
|
+
An Automation page checks three things inside the page, not in the layout, so a Host that replaces the layout keeps the check:
|
|
296
|
+
|
|
297
|
+
1. **The Automations context**: `defineAutomationsContext()` was called.
|
|
298
|
+
2. **An Automation Catalog for the Host's Product**: the backend serves one for the `product` of the composer context.
|
|
299
|
+
3. **An Organization**: the layer resolved one (see "Organization and WABA").
|
|
64
300
|
|
|
65
|
-
|
|
66
|
-
pnpm preview
|
|
301
|
+
With the flag on and one of them missing, the page keeps its header and shows an error alert in place of its content. A failed Organization lookup or a failed catalog request shows the same alert with a retry.
|
|
67
302
|
|
|
68
|
-
|
|
69
|
-
yarn preview
|
|
303
|
+
The layer ships **no permission check** on these pages: the Host guards them as it guards the Message pages.
|
|
70
304
|
|
|
71
|
-
|
|
72
|
-
|
|
305
|
+
A Host sees only the Automations of its own Product. The Channels an Action can send over are the ones the catalog gives its Trigger, limited to the `channels` of the composer context, and WhatsApp only when the Organization has a WABA.
|
|
306
|
+
|
|
307
|
+
### Public and stable
|
|
308
|
+
|
|
309
|
+
This is the host contract for Automations:
|
|
310
|
+
|
|
311
|
+
- the `composer.automations` flag;
|
|
312
|
+
- the three route names: `automations-list`, `automation-create`, `automation-edit`;
|
|
313
|
+
- `defineAutomationsContext()` and the shape of `AutomationsContext`;
|
|
314
|
+
- `FiltersEditor` and `FiltersSummary`, with their props and emits;
|
|
315
|
+
- the `fields` shape and the report: `FilterField`, `FilterOption`, `FiltersReport`;
|
|
316
|
+
- `useBuiltInOptionLists()`;
|
|
317
|
+
- the shared schemas in `@dev.smartpricing/message-composer-utils/schemas`: the Condition schemas (`conditionSchema`, `conditionOperatorSchema`, `conditionFieldTypeSchema`), the request and response schemas of the Automation routes and of the Automation Catalog, and with them the operator table `CONDITION_OPERATORS_BY_FIELD_TYPE` (in `/types`).
|
|
318
|
+
|
|
319
|
+
The semver promise (ADRs [0018](../../docs/adr/0018-filter-components-speak-conditions-and-know-no-catalog.md) and [0019](../../docs/adr/0019-automation-pages-off-until-a-host-turns-them-on.md)):
|
|
320
|
+
|
|
321
|
+
- **Major**: renaming or removing a route name; removing or renaming a prop of a filter component; changing the shape of the value (`Condition[]`); dropping a field type or an operator.
|
|
322
|
+
- **Minor**: adding a prop, a field type or an operator.
|
|
323
|
+
- **No promise**: the paths (the Host's to remap), everything else under `app/components/Filters/` and `app/utils/filters/`, and the test-id pattern. They can change in any release. The components and utils of the pages themselves (`app/components/Automations/`, `app/utils/automations/`) are not on the list above.
|
|
324
|
+
|
|
325
|
+
The flag, the context and the shared schemas are host contract with no rule of their own in the ADRs: the general one applies (see "Release": a change to the host contract is a major).
|
|
326
|
+
|
|
327
|
+
## Filter components
|
|
328
|
+
|
|
329
|
+
Two props-only components edit and show a list of Conditions in the Automation Engine's shape (`{ field, operator, value? }`), on any page: they read neither the Automation Catalog nor the Host's context ([ADR 0018](../../docs/adr/0018-filter-components-speak-conditions-and-know-no-catalog.md)). The slideover, Save and Cancel around the editor belong to the page.
|
|
330
|
+
|
|
331
|
+
```vue
|
|
332
|
+
<script setup lang="ts">
|
|
333
|
+
import type {
|
|
334
|
+
Condition,
|
|
335
|
+
FilterField,
|
|
336
|
+
FiltersReport,
|
|
337
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
338
|
+
|
|
339
|
+
const { countries } = useBuiltInOptionLists()
|
|
340
|
+
|
|
341
|
+
const fields = computed<FilterField[]>(() => [
|
|
342
|
+
{ key: 'guest.country', label: t('country'), type: 'multiselect', options: countries.value },
|
|
343
|
+
{ key: 'totalPrice', label: t('total_price'), type: 'price' },
|
|
344
|
+
])
|
|
345
|
+
const conditions = ref<Condition[]>([])
|
|
346
|
+
const report = ref<FiltersReport>()
|
|
347
|
+
</script>
|
|
348
|
+
|
|
349
|
+
<template>
|
|
350
|
+
<FiltersEditor v-model="conditions" :fields="fields" title="Audience" @report="report = $event" />
|
|
351
|
+
<FiltersSummary :model-value="conditions" :fields="fields" />
|
|
352
|
+
</template>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
| Auto-import name | Props | Emits |
|
|
356
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
357
|
+
| `FiltersEditor` | `v-model` (`Condition[]`), `fields`, `currency?`, `title?`, `subtitle?`, `testIdPrefix?` | `update:modelValue`, `report` |
|
|
358
|
+
| `FiltersSummary` | `modelValue` (`Condition[]`), `fields`, `currency?`, `preview?` (lines before "View more", 3), `testIdPrefix?` | `report` |
|
|
359
|
+
| `useBuiltInOptionLists()` | returns `countries` and `languages`: option lists in the current language, values are lowercase ISO codes | - |
|
|
360
|
+
|
|
361
|
+
- **`fields`** is one reactive list of `{ key, label, type, options? }`, labels and options already resolved, in display order. `type` is one of `select`, `multiselect`, `number`, `price`, `date`, `text`; the operators of each are `CONDITION_OPERATORS_BY_FIELD_TYPE` in `message-composer-utils`. A field can be picked once.
|
|
362
|
+
- **Values**: a `price` is stored in cents and shown in `currency` (EUR when absent, never converted); a `date` is `YYYY-MM-DD`. "Between" is a `gte` and an `lte` on the same field. There is no "not between": the Automation Engine holds all the Conditions of a list together, so no pair of them can say "outside this range". A stored `lte` below a `gte` on one field shows as one editable row and one unavailable row.
|
|
363
|
+
- **Nothing is dropped.** A Condition on a field that is not in `fields`, with an operator or a value that does not fit the field's type, or one too many on a field, shows as an unavailable row: emitted as it came in until the user removes it. A selected option that is not in `options` shows as unavailable and is kept the same way. A row the user did not touch is emitted exactly as stored.
|
|
364
|
+
- **`report`** (`FiltersReport`, emitted on mount and on every change): `unknownFields`, `unavailable` (each Condition with its reason, `unknown_field` or `not_editable`), `unavailableOptions`, and `halfFilled`, the rows with a field and no complete value. A half-filled row is never in the emitted value. The components block nothing: the caller decides what stops a save.
|
|
365
|
+
- **Rows in progress** live in the editor only. It reads its rows again when the Conditions change from outside or when the keys or types in `fields` change, and rows in progress are then lost. Setting `v-model` to the value it already has does not reset them: to start over, remount the editor with a `key`.
|
|
366
|
+
- **Stability**: the two components, the `fields` shape, the report (`FilterField`, `FilterOption` and `FiltersReport`, in `message-composer-utils/types`), `useBuiltInOptionLists()` and the Condition schemas are host contract, usable before the Automation pages are turned on. What is a major and what is a minor is in "Public and stable" above.
|
|
367
|
+
- **Dev harness**: `/debug/filters` in `apps/frontend`.
|
|
368
|
+
|
|
369
|
+
## Development
|
|
370
|
+
|
|
371
|
+
Run from `apps/layer`:
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
pnpm typecheck # nuxt typecheck
|
|
375
|
+
pnpm lint # eslint app/ --fix
|
|
376
|
+
pnpm test:e2e # playwright
|
|
377
|
+
pnpm translations:check # every locale has every key
|
|
73
378
|
```
|
|
74
379
|
|
|
75
|
-
|
|
380
|
+
There is no dev server in the layer itself: use `apps/frontend`, which extends `../layer`.
|
|
381
|
+
|
|
382
|
+
## Release
|
|
383
|
+
|
|
384
|
+
1. Bump `version` in `apps/layer/package.json` and `packages/message-composer-utils/package.json` together (semver: minor for a new component or prop, major for a change to the host contract).
|
|
385
|
+
2. Build the tarball from `apps/layer` with `pnpm pack`; `build.sh` builds the Docker image of the standalone deployment, not the npm package.
|
|
386
|
+
3. Publish both packages to the private registry.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Automation,
|
|
3
|
+
AutomationCatalogLanguage,
|
|
4
|
+
AutomationCatalogResponse,
|
|
5
|
+
AutomationDeleteResult,
|
|
6
|
+
CloneAutomationBody,
|
|
7
|
+
CreateAutomationBody,
|
|
8
|
+
MessageGroupProduct,
|
|
9
|
+
UpdateAutomationBody,
|
|
10
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
11
|
+
import { apiClient } from './client'
|
|
12
|
+
|
|
13
|
+
/** Every request names its Organization and its Product (ADR 0014, ADR 0019). */
|
|
14
|
+
export const automationsApi = {
|
|
15
|
+
getAll: (options: { organization_id: string; product: MessageGroupProduct }) =>
|
|
16
|
+
apiClient<Automation[]>(`/automations?${new URLSearchParams(options)}`),
|
|
17
|
+
|
|
18
|
+
getCatalog: (options: {
|
|
19
|
+
organization_id: string
|
|
20
|
+
product: MessageGroupProduct
|
|
21
|
+
language: AutomationCatalogLanguage
|
|
22
|
+
}) => apiClient<AutomationCatalogResponse>(`/automation-catalog?${new URLSearchParams(options)}`),
|
|
23
|
+
|
|
24
|
+
/** No error toast: the page says in place why it has no Automation to show. */
|
|
25
|
+
getById: (id: string, options: { product: MessageGroupProduct }) =>
|
|
26
|
+
apiClient<Automation>(
|
|
27
|
+
`/automations/${encodeURIComponent(id)}?${new URLSearchParams(options)}`,
|
|
28
|
+
{
|
|
29
|
+
_skipErrorToast: true,
|
|
30
|
+
} as Record<string, unknown>,
|
|
31
|
+
),
|
|
32
|
+
|
|
33
|
+
/** No error toast: a refused save is shown in the form, by its caller. */
|
|
34
|
+
create: (body: CreateAutomationBody) =>
|
|
35
|
+
apiClient<Automation>('/automations', {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
body,
|
|
38
|
+
_skipErrorToast: true,
|
|
39
|
+
} as Record<string, unknown>),
|
|
40
|
+
|
|
41
|
+
/** No error toast, as on a create: its caller tells a refused save from a half-saved one. */
|
|
42
|
+
update: (id: string, body: UpdateAutomationBody) =>
|
|
43
|
+
apiClient<Automation>(`/automations/${encodeURIComponent(id)}`, {
|
|
44
|
+
method: 'PUT',
|
|
45
|
+
body,
|
|
46
|
+
_skipErrorToast: true,
|
|
47
|
+
} as Record<string, unknown>),
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The copy of an Automation, made by the backend from what is stored: with
|
|
51
|
+
* its own Message Groups and every Action inactive (ADR 0016).
|
|
52
|
+
*/
|
|
53
|
+
clone: (id: string, body: CloneAutomationBody) =>
|
|
54
|
+
apiClient<Automation>(`/automations/${encodeURIComponent(id)}/clone`, {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
body,
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Deletes the Automation and the Message Groups named, each a repeated
|
|
61
|
+
* `message_group_ids`. With none the answer is empty; with some it says
|
|
62
|
+
* which were deleted and which were kept (ADR 0016).
|
|
63
|
+
*/
|
|
64
|
+
delete: (id: string, options: { product: MessageGroupProduct; message_group_ids: string[] }) => {
|
|
65
|
+
const query = new URLSearchParams({ product: options.product })
|
|
66
|
+
for (const messageGroupId of options.message_group_ids) {
|
|
67
|
+
query.append('message_group_ids', messageGroupId)
|
|
68
|
+
}
|
|
69
|
+
return apiClient<AutomationDeleteResult | undefined>(
|
|
70
|
+
`/automations/${encodeURIComponent(id)}?${query}`,
|
|
71
|
+
{ method: 'DELETE' },
|
|
72
|
+
)
|
|
73
|
+
},
|
|
74
|
+
}
|
package/app/api/brands.ts
CHANGED
|
@@ -14,19 +14,27 @@ import { apiClient } from './client'
|
|
|
14
14
|
export type BrandWithProperties = BrandFromDb & { properties: BrandProperty[] }
|
|
15
15
|
export type BrandCreateResponse = BrandFromDb & { brand_count: number }
|
|
16
16
|
export type BrandDeleteResponse = { brand_count: number }
|
|
17
|
+
export type BrandPreviewRequest = {
|
|
18
|
+
message: PostEntity<EmailMessage>
|
|
19
|
+
parameters?: Record<string, unknown>
|
|
20
|
+
brand?: BrandCascadeData | undefined
|
|
21
|
+
}
|
|
17
22
|
|
|
18
23
|
export const brandsApi = {
|
|
19
|
-
getAll: (options
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
getAll: (options: {
|
|
25
|
+
organization_id: string
|
|
26
|
+
sort_by?: 'created_at' | 'name'
|
|
27
|
+
direction?: 'asc' | 'desc'
|
|
28
|
+
}) => {
|
|
29
|
+
const params = new URLSearchParams({ organization_id: options.organization_id })
|
|
30
|
+
if (options.sort_by) params.set('sort_by', options.sort_by)
|
|
31
|
+
if (options.direction) params.set('direction', options.direction)
|
|
32
|
+
return apiClient<BrandWithProperties[]>(`/brands?${params.toString()}`)
|
|
25
33
|
},
|
|
26
34
|
|
|
27
35
|
getById: (id: string) => apiClient<BrandWithProperties>(`/brands/${id}`),
|
|
28
36
|
|
|
29
|
-
create: (data: BrandCreateBody) =>
|
|
37
|
+
create: (data: BrandCreateBody & { organization_id: string }) =>
|
|
30
38
|
apiClient<BrandCreateResponse>('/brands', {
|
|
31
39
|
method: 'POST',
|
|
32
40
|
body: data,
|
|
@@ -43,11 +51,7 @@ export const brandsApi = {
|
|
|
43
51
|
|
|
44
52
|
delete: (id: string) => apiClient<BrandDeleteResponse>(`/brands/${id}`, { method: 'DELETE' }),
|
|
45
53
|
|
|
46
|
-
preview: (data: {
|
|
47
|
-
message: PostEntity<EmailMessage>
|
|
48
|
-
parameters?: Record<string, unknown>
|
|
49
|
-
brand?: BrandCascadeData | undefined
|
|
50
|
-
}) =>
|
|
54
|
+
preview: (data: BrandPreviewRequest & { organization_id: string }) =>
|
|
51
55
|
apiClient<CompileEmailResponse>('/message-groups/preview', {
|
|
52
56
|
method: 'POST',
|
|
53
57
|
body: data,
|
|
@@ -55,5 +59,8 @@ export const brandsApi = {
|
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
export const propertiesApi = {
|
|
58
|
-
getAll: () =>
|
|
62
|
+
getAll: (organizationId: string) =>
|
|
63
|
+
apiClient<Property[]>(
|
|
64
|
+
`/properties?${new URLSearchParams({ organization_id: organizationId })}`,
|
|
65
|
+
),
|
|
59
66
|
}
|
package/app/api/client.ts
CHANGED
|
@@ -24,19 +24,21 @@ export const apiClient = createApiClient({
|
|
|
24
24
|
(useRuntimeConfig().public.BACKEND_BASE_URL as string) ||
|
|
25
25
|
(useRuntimeConfig().public.PLATFORM_URL as string),
|
|
26
26
|
platformURL: useRuntimeConfig().public.PLATFORM_URL as string,
|
|
27
|
+
// The composer backend answers a dead access token with @fastify/jwt's flat
|
|
28
|
+
// body (`code: FST_JWT_*` at top level), never the platform's nested
|
|
29
|
+
// `error.code: session.*` that the default predicate looks for. Refresh on
|
|
30
|
+
// any 401, as Connect's client does; the retry decides.
|
|
31
|
+
shouldRefresh: (status) => status === 401,
|
|
27
32
|
onRefreshFailed: () => {
|
|
28
33
|
useNuxtApp().callHook('composer:auth-error', { statusCode: 401 })
|
|
29
34
|
},
|
|
30
35
|
},
|
|
36
|
+
// No Organization header: every request names its Organization itself, in
|
|
37
|
+
// the query, in the body or through the resource it acts on (ADR 0014).
|
|
38
|
+
// No WABA header either: a submission names its WABA in the body (ADR 0015).
|
|
31
39
|
onRequest({ options }) {
|
|
32
40
|
const store = useAppContextStore()
|
|
33
41
|
|
|
34
|
-
if (store.organization_id) {
|
|
35
|
-
options.headers.set('sm-organization-id', store.organization_id)
|
|
36
|
-
}
|
|
37
|
-
if (store.metaWabaId) {
|
|
38
|
-
options.headers.set('x-meta-waba-id', store.metaWabaId)
|
|
39
|
-
}
|
|
40
42
|
if (store.product) {
|
|
41
43
|
options.headers.set('sm-product', store.product)
|
|
42
44
|
}
|
|
@@ -45,6 +47,13 @@ export const apiClient = createApiClient({
|
|
|
45
47
|
}
|
|
46
48
|
},
|
|
47
49
|
onResponseError({ response, options }) {
|
|
50
|
+
// A 401 that reaches here survived the refresh attempt (or its retry): the
|
|
51
|
+
// session is dead. platform-layer only calls onRefreshFailed for its own
|
|
52
|
+
// `session.*` codes, so tell the host here for the composer's `FST_JWT_*`.
|
|
53
|
+
if (response.status === 401) {
|
|
54
|
+
useNuxtApp().callHook('composer:auth-error', { statusCode: 401 })
|
|
55
|
+
return
|
|
56
|
+
}
|
|
48
57
|
if ((options as { _skipErrorToast?: boolean })._skipErrorToast) return
|
|
49
58
|
|
|
50
59
|
const t = useNuxtApp().$i18n.t
|