@dev.smartpricing/message-composer-layer 4.1.1 → 4.2.1

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/app/api/client.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { ofetch } from 'ofetch'
2
1
  import type { AppError } from '@dev.smartpricing/message-composer-utils/types'
3
2
  import { useAppContextStore } from '@/stores/appContext'
4
3
 
@@ -12,16 +11,25 @@ function assertAppError(data: unknown): data is AppError {
12
11
  return false
13
12
  }
14
13
 
15
- export const apiClient = ofetch.create({
16
- baseURL: useRuntimeConfig().public.COMPOSER_API_URL,
14
+ export const apiClient = createApiClient({
15
+ baseURL: useRuntimeConfig().public.COMPOSER_API_URL as string,
16
+ csrf: {
17
+ cookieName: (useRuntimeConfig().public.ENV_CSRF_COOKIE_NAME as string) || 'smt_csrf',
18
+ },
19
+ auth: {
20
+ refreshBaseURL:
21
+ (useRuntimeConfig().public.BACKEND_BASE_URL as string) ||
22
+ (useRuntimeConfig().public.PLATFORM_URL as string),
23
+ platformURL: useRuntimeConfig().public.PLATFORM_URL as string,
24
+ onRefreshFailed: () => {
25
+ useNuxtApp().callHook('composer:auth-error', { statusCode: 401 })
26
+ },
27
+ },
17
28
  onRequest({ options }) {
18
29
  const store = useAppContextStore()
19
30
 
20
- if (store.authenticationToken) {
21
- options.headers.set('Authorization', `Bearer ${store.authenticationToken}`)
22
- }
23
- if (store.owner_id) {
24
- options.headers.set('sm-owner', store.owner_id)
31
+ if (store.organization_id) {
32
+ options.headers.set('sm-organization-id', store.organization_id)
25
33
  }
26
34
  if (store.metaWabaId) {
27
35
  options.headers.set('x-meta-waba-id', store.metaWabaId)
@@ -33,11 +41,7 @@ export const apiClient = ofetch.create({
33
41
  options.headers.set('sm-default-tags', store.default_tags.join(','))
34
42
  }
35
43
  },
36
- async onResponseError({ response }) {
37
- if (response.status === 401) {
38
- await useNuxtApp().callHook('composer:auth-error', { statusCode: 401 })
39
- }
40
-
44
+ onResponseError({ response }) {
41
45
  const error = response._data
42
46
  if (assertAppError(error)) {
43
47
  useToast().add({
@@ -8,7 +8,11 @@ import type {
8
8
  GenerateTextWidgetType,
9
9
  RefineTextResponse,
10
10
  } from '@dev.smartpricing/message-composer-utils/types'
11
- import { convertToWhatsappMarkdown } from '@dev.smartpricing/message-composer-utils/utils'
11
+ import {
12
+ convertToWhatsappMarkdown,
13
+ getTipTapExtensions,
14
+ sanitizeContent,
15
+ } from '@dev.smartpricing/message-composer-utils/utils'
12
16
  import EmojiPickerButton from '../Common/EmojiPickerButton.vue'
13
17
  import DynamicDataSlideover from '../DynamicDataSlideover.vue'
14
18
  import EditorLinkPopover from './EditorLinkPopover.vue'
@@ -350,6 +354,16 @@ function isEmpty() {
350
354
  return getHtml() === '' || editor.value?.isEmpty
351
355
  }
352
356
 
357
+ function sanitizeEditor() {
358
+ const val = toValue(text)
359
+ if (!val) return
360
+ const clean = sanitizeContent(val, getTipTapExtensions({ preset: props.preset }))
361
+
362
+ if (clean !== val) {
363
+ text.value = clean
364
+ }
365
+ }
366
+
353
367
  defineExpose({
354
368
  editor,
355
369
  setFocus,
@@ -372,6 +386,8 @@ defineExpose({
372
386
  :on-update="handleUpdate as any"
373
387
  :mention="false"
374
388
  :on-blur="handleBlur"
389
+ enable-content-check
390
+ :onContentError="sanitizeEditor"
375
391
  :placeholder="$t('editor.placeholder.insert_text')"
376
392
  :data-testid="richTextEditorTestIds.editor"
377
393
  >
@@ -6,7 +6,10 @@ import type {
6
6
  } from '@dev.smartpricing/message-composer-utils/types'
7
7
  import { generateHTML } from '@tiptap/vue-3'
8
8
  import { computed } from 'vue'
9
- import { getTipTapExtensions } from '@dev.smartpricing/message-composer-utils/utils'
9
+ import {
10
+ generateWhatsappHtml,
11
+ getTipTapExtensions,
12
+ } from '@dev.smartpricing/message-composer-utils/utils'
10
13
  import { useResolvedParametersQuery } from '~/queries/compilation'
11
14
 
12
15
  defineOptions({
@@ -38,10 +41,10 @@ function replaceMentionsWithValues(html: string): string {
38
41
 
39
42
  const bodyHtml = computed(() => {
40
43
  if (!props.message.body.body.content) return ''
41
- const html = generateHTML(
42
- props.message.body.body.content,
43
- getTipTapExtensions({ preset: 'whatsapp' }),
44
- ).replaceAll('<p></p>', '<p>&nbsp;</p>')
44
+ const html = generateWhatsappHtml(props.message.body.body.content).replaceAll(
45
+ '<p></p>',
46
+ '<p>&nbsp;</p>',
47
+ )
45
48
  return replaceMentionsWithValues(html)
46
49
  })
47
50
 
@@ -6,8 +6,9 @@ export interface OrganizationData {
6
6
  }
7
7
 
8
8
  export interface ComposerContext {
9
- authenticationToken: Ref<string>
10
- owner_id?: Ref<string>
9
+ /** @deprecated No longer used — auth is cookie-based via platform layer */
10
+ authenticationToken?: Ref<string>
11
+ organization_id?: Ref<string>
11
12
  product?: Ref<AppContextConfig['product']>
12
13
  strategy?: Ref<AppContextConfig['strategy']>
13
14
  channels?: Ref<AppContextConfig['channels']>
@@ -29,9 +30,7 @@ export function defineComposerContext(context: ComposerContext): void {
29
30
  useNuxtApp().vueApp.provide(COMPOSER_CONTEXT_KEY, context)
30
31
  }
31
32
 
32
- const SERVER_FALLBACK: ComposerContext = {
33
- authenticationToken: ref(''),
34
- }
33
+ const SERVER_FALLBACK: ComposerContext = {}
35
34
 
36
35
  export function useComposerContext(): ComposerContext {
37
36
  if (import.meta.server) return SERVER_FALLBACK
@@ -10,8 +10,7 @@ export const useAppContextStore = defineStore('appContext', () => {
10
10
  const isInitialized = ref<boolean>(false)
11
11
 
12
12
  // Proxy from injection with defaults (same interface as before)
13
- const authenticationToken = computed(() => ctx.authenticationToken.value)
14
- const owner_id = computed(() => ctx.owner_id?.value ?? '')
13
+ const organization_id = computed(() => ctx.organization_id?.value ?? '')
15
14
  const product = computed<NonNullable<AppContextConfig['product']>>(
16
15
  () => ctx.product?.value ?? 'browser',
17
16
  )
@@ -44,7 +43,6 @@ export const useAppContextStore = defineStore('appContext', () => {
44
43
 
45
44
  // Computed context object for convenience
46
45
  const context = computed<AppContextState>(() => ({
47
- authenticationToken: authenticationToken.value,
48
46
  product: product.value,
49
47
  strategy: strategy.value,
50
48
  channels: channels.value,
@@ -52,7 +50,7 @@ export const useAppContextStore = defineStore('appContext', () => {
52
50
  mainLanguage: mainLanguage.value,
53
51
  metaWabaId: metaWabaId.value,
54
52
  metaAccessToken: metaAccessToken.value,
55
- owner_id: owner_id.value,
53
+ organization_id: organization_id.value,
56
54
  default_tags: default_tags.value,
57
55
  initializationSource: 'injection',
58
56
  }))
@@ -61,10 +59,6 @@ export const useAppContextStore = defineStore('appContext', () => {
61
59
  const validationErrors = computed<Record<string, string>>(() => {
62
60
  const errors: Record<string, string> = {}
63
61
 
64
- if (!authenticationToken.value) {
65
- errors.authenticationToken = 'Authentication token is required'
66
- }
67
-
68
62
  if (channels.value?.includes('whatsapp') && !metaWabaId.value) {
69
63
  errors.metaConfig = 'Meta WABA ID is required for WhatsApp'
70
64
  }
@@ -78,7 +72,6 @@ export const useAppContextStore = defineStore('appContext', () => {
78
72
  }
79
73
 
80
74
  return {
81
- authenticationToken,
82
75
  product,
83
76
  strategy,
84
77
  channels,
@@ -87,7 +80,7 @@ export const useAppContextStore = defineStore('appContext', () => {
87
80
  dinamicValues,
88
81
  metaWabaId,
89
82
  metaAccessToken,
90
- owner_id,
83
+ organization_id,
91
84
  default_tags,
92
85
  isAdmin,
93
86
 
@@ -34,7 +34,6 @@ export const useEmailComposerStore = defineStore('emailComposer', () => {
34
34
 
35
35
  // ── Computed ──────────────────────────────────────────────────────
36
36
  const messageGroupData = computed(() => ({
37
- user_id: '',
38
37
  name: name.value,
39
38
  category: category.value,
40
39
  visibility: isInternal.value ? 'internal' : 'public',
package/nuxt.config.ts CHANGED
@@ -5,11 +5,10 @@ export default defineNuxtConfig({
5
5
  viteEnvironmentApi: true,
6
6
  },
7
7
  devtools: { enabled: true },
8
- modules: ['@pinia/nuxt', '@nuxtjs/i18n', '@pinia/colada-nuxt'],
9
8
  imports: {
10
9
  dirs: ['stores', 'queries'],
11
10
  },
12
- extends: ['nuxt-ui-layer'],
11
+ extends: ['@dev.smartpricing/platform-layer'],
13
12
  i18n: {
14
13
  strategy: 'no_prefix',
15
14
  locales: [
@@ -46,11 +45,9 @@ export default defineNuxtConfig({
46
45
  ],
47
46
  detectBrowserLanguage: {
48
47
  useCookie: true,
49
- cookieKey: 'i18n_redirected',
48
+ cookieKey: 'smt_lang',
50
49
  fallbackLocale: 'en',
51
50
  cookieDomain: process.env.NUXT_PUBLIC_COOKIE_DOMAIN || undefined,
52
- cookieCrossOrigin: true,
53
- cookieSecure: false,
54
51
  },
55
52
  defaultLocale: 'en',
56
53
  compilation: {
@@ -60,6 +57,9 @@ export default defineNuxtConfig({
60
57
  runtimeConfig: {
61
58
  public: {
62
59
  COMPOSER_API_URL: '',
60
+ BACKEND_BASE_URL: '',
61
+ PLATFORM_URL: '',
62
+ ENV_CSRF_COOKIE_NAME: 'smt_csrf',
63
63
  },
64
64
  },
65
65
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev.smartpricing/message-composer-layer",
3
- "version": "4.1.1",
3
+ "version": "4.2.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -12,11 +12,9 @@
12
12
  "app.config.ts"
13
13
  ],
14
14
  "dependencies": {
15
+ "@dev.smartpricing/platform-layer": "^0.0.8",
15
16
  "@formkit/drag-and-drop": "^0.5.3",
16
- "@nuxtjs/i18n": "^10.3.0",
17
17
  "@pinia/colada": "^1.3.0",
18
- "@pinia/colada-nuxt": "^1.0.1",
19
- "@pinia/nuxt": "^0.11.3",
20
18
  "@tiptap/extension-character-count": "^3.23.4",
21
19
  "@tiptap/extension-emoji": "^3.23.4",
22
20
  "@tiptap/extension-link": "^3.23.4",
@@ -38,14 +36,14 @@
38
36
  "vue-router": "^5.0.7",
39
37
  "vue3-emoji-picker": "^1.1.8",
40
38
  "zod": "^4.4.3",
41
- "@dev.smartpricing/message-composer-utils": "4.1.1"
39
+ "@dev.smartpricing/message-composer-utils": "4.2.1"
42
40
  },
43
41
  "devDependencies": {
44
42
  "@nuxt/eslint": "^1.15.2",
45
43
  "@nuxt/test-utils": "^4.0.3",
46
44
  "@playwright/test": "^1.60.0",
47
45
  "dotenv": "^17.4.2",
48
- "nuxt-ui-layer": "git+ssh://git@github.com:smartpricing/smartness-nuxt-ui#v1.6.6",
46
+ "nuxt-ui-layer": "git+ssh://git@github.com:smartpricing/smartness-nuxt-ui#v1.7.2",
49
47
  "vue-tsc": "^3.2.9"
50
48
  },
51
49
  "peerDependencies": {
@@ -53,7 +51,6 @@
53
51
  },
54
52
  "scripts": {
55
53
  "build": "nuxt build",
56
- "dev": "nuxt dev",
57
54
  "lint": "eslint app/ --fix",
58
55
  "format": "prettier --write app/",
59
56
  "typecheck": "nuxt typecheck",