@justanarthur/payload-plugin-translator 1.3.20 → 1.3.21

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.
Files changed (128) hide show
  1. package/dist/client.d.ts +6 -0
  2. package/dist/client.js +320 -0
  3. package/dist/index.d.ts +102 -11
  4. package/dist/index.js +1294 -80
  5. package/dist/jobs.d.ts +195 -0
  6. package/dist/jobs.js +824 -0
  7. package/dist/resolvers/copy.d.ts +21 -3
  8. package/dist/resolvers/copy.js +18 -12
  9. package/dist/resolvers/google.d.ts +29 -11
  10. package/dist/resolvers/google.js +58 -44
  11. package/dist/resolvers/libreTranslate.d.ts +33 -15
  12. package/dist/resolvers/libreTranslate.js +60 -45
  13. package/dist/resolvers/openAI.d.ts +39 -21
  14. package/dist/resolvers/openAI.js +110 -114
  15. package/dist/resolvers/types.d.ts +16 -16
  16. package/dist/resolvers/types.js +0 -3
  17. package/dist/{client/components/CustomButton/styles.scss → styles-jt3fm5fh.scss} +5 -5
  18. package/dist/{client/components/TranslatorModal/styles.scss → styles-vs6m7h55.scss} +76 -76
  19. package/dist/types.d.ts +70 -22
  20. package/dist/types.js +0 -3
  21. package/package.json +87 -64
  22. package/README.md +0 -215
  23. package/dist/client/api/index.d.ts +0 -8
  24. package/dist/client/api/index.d.ts.map +0 -1
  25. package/dist/client/api/index.js +0 -28
  26. package/dist/client/api/index.js.map +0 -1
  27. package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts +0 -5
  28. package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts.map +0 -1
  29. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js +0 -28
  30. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js.map +0 -1
  31. package/dist/client/components/CustomButton/index.d.ts +0 -3
  32. package/dist/client/components/CustomButton/index.d.ts.map +0 -1
  33. package/dist/client/components/CustomButton/index.js +0 -10
  34. package/dist/client/components/CustomButton/index.js.map +0 -1
  35. package/dist/client/components/LocaleLabel/LocaleLabel.d.ts +0 -5
  36. package/dist/client/components/LocaleLabel/LocaleLabel.d.ts.map +0 -1
  37. package/dist/client/components/LocaleLabel/LocaleLabel.js +0 -28
  38. package/dist/client/components/LocaleLabel/LocaleLabel.js.map +0 -1
  39. package/dist/client/components/LocaleLabel/index.d.ts +0 -2
  40. package/dist/client/components/LocaleLabel/index.d.ts.map +0 -1
  41. package/dist/client/components/LocaleLabel/index.js +0 -3
  42. package/dist/client/components/LocaleLabel/index.js.map +0 -1
  43. package/dist/client/components/ResolverButton/ResolverButton.d.ts +0 -5
  44. package/dist/client/components/ResolverButton/ResolverButton.d.ts.map +0 -1
  45. package/dist/client/components/ResolverButton/ResolverButton.js +0 -16
  46. package/dist/client/components/ResolverButton/ResolverButton.js.map +0 -1
  47. package/dist/client/components/ResolverButton/index.d.ts +0 -2
  48. package/dist/client/components/ResolverButton/index.d.ts.map +0 -1
  49. package/dist/client/components/ResolverButton/index.js +0 -3
  50. package/dist/client/components/ResolverButton/index.js.map +0 -1
  51. package/dist/client/components/TranslatorModal/Content.d.ts +0 -2
  52. package/dist/client/components/TranslatorModal/Content.d.ts.map +0 -1
  53. package/dist/client/components/TranslatorModal/Content.js +0 -60
  54. package/dist/client/components/TranslatorModal/Content.js.map +0 -1
  55. package/dist/client/components/TranslatorModal/TranslatorModal.d.ts +0 -3
  56. package/dist/client/components/TranslatorModal/TranslatorModal.d.ts.map +0 -1
  57. package/dist/client/components/TranslatorModal/TranslatorModal.js +0 -26
  58. package/dist/client/components/TranslatorModal/TranslatorModal.js.map +0 -1
  59. package/dist/client/components/TranslatorModal/index.d.ts +0 -2
  60. package/dist/client/components/TranslatorModal/index.d.ts.map +0 -1
  61. package/dist/client/components/TranslatorModal/index.js +0 -3
  62. package/dist/client/components/TranslatorModal/index.js.map +0 -1
  63. package/dist/client/providers/Translator/TranslatorProvider.d.ts +0 -5
  64. package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +0 -1
  65. package/dist/client/providers/Translator/TranslatorProvider.js +0 -109
  66. package/dist/client/providers/Translator/TranslatorProvider.js.map +0 -1
  67. package/dist/client/providers/Translator/context.d.ts +0 -21
  68. package/dist/client/providers/Translator/context.d.ts.map +0 -1
  69. package/dist/client/providers/Translator/context.js +0 -9
  70. package/dist/client/providers/Translator/context.js.map +0 -1
  71. package/dist/exports/client.d.ts +0 -2
  72. package/dist/exports/client.d.ts.map +0 -1
  73. package/dist/exports/client.js +0 -3
  74. package/dist/exports/client.js.map +0 -1
  75. package/dist/i18n-translations.d.ts +0 -87
  76. package/dist/i18n-translations.d.ts.map +0 -1
  77. package/dist/i18n-translations.js +0 -88
  78. package/dist/i18n-translations.js.map +0 -1
  79. package/dist/index.d.ts.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/resolvers/copy.d.ts.map +0 -1
  82. package/dist/resolvers/copy.js.map +0 -1
  83. package/dist/resolvers/google.d.ts.map +0 -1
  84. package/dist/resolvers/google.js.map +0 -1
  85. package/dist/resolvers/libreTranslate.d.ts.map +0 -1
  86. package/dist/resolvers/libreTranslate.js.map +0 -1
  87. package/dist/resolvers/openAI.d.ts.map +0 -1
  88. package/dist/resolvers/openAI.js.map +0 -1
  89. package/dist/resolvers/types.d.ts.map +0 -1
  90. package/dist/resolvers/types.js.map +0 -1
  91. package/dist/translate/endpoint.d.ts +0 -3
  92. package/dist/translate/endpoint.d.ts.map +0 -1
  93. package/dist/translate/endpoint.js +0 -23
  94. package/dist/translate/endpoint.js.map +0 -1
  95. package/dist/translate/findEntityWithConfig.d.ts +0 -16
  96. package/dist/translate/findEntityWithConfig.d.ts.map +0 -1
  97. package/dist/translate/findEntityWithConfig.js +0 -34
  98. package/dist/translate/findEntityWithConfig.js.map +0 -1
  99. package/dist/translate/operation.d.ts +0 -9
  100. package/dist/translate/operation.d.ts.map +0 -1
  101. package/dist/translate/operation.js +0 -78
  102. package/dist/translate/operation.js.map +0 -1
  103. package/dist/translate/traverseFields.d.ts +0 -17
  104. package/dist/translate/traverseFields.d.ts.map +0 -1
  105. package/dist/translate/traverseFields.js +0 -233
  106. package/dist/translate/traverseFields.js.map +0 -1
  107. package/dist/translate/traverseRichText.d.ts +0 -10
  108. package/dist/translate/traverseRichText.d.ts.map +0 -1
  109. package/dist/translate/traverseRichText.js +0 -24
  110. package/dist/translate/traverseRichText.js.map +0 -1
  111. package/dist/translate/types.d.ts +0 -27
  112. package/dist/translate/types.d.ts.map +0 -1
  113. package/dist/translate/types.js +0 -3
  114. package/dist/translate/types.js.map +0 -1
  115. package/dist/translate/updateEntity.d.ts +0 -14
  116. package/dist/translate/updateEntity.d.ts.map +0 -1
  117. package/dist/translate/updateEntity.js +0 -26
  118. package/dist/translate/updateEntity.js.map +0 -1
  119. package/dist/types.d.ts.map +0 -1
  120. package/dist/types.js.map +0 -1
  121. package/dist/utils/chunkArray.d.ts +0 -2
  122. package/dist/utils/chunkArray.d.ts.map +0 -1
  123. package/dist/utils/chunkArray.js +0 -7
  124. package/dist/utils/chunkArray.js.map +0 -1
  125. package/dist/utils/isEmpty.d.ts +0 -2
  126. package/dist/utils/isEmpty.d.ts.map +0 -1
  127. package/dist/utils/isEmpty.js +0 -8
  128. package/dist/utils/isEmpty.js.map +0 -1
package/dist/jobs.d.ts ADDED
@@ -0,0 +1,195 @@
1
+ import { CollectionAfterChangeHook } from "payload";
2
+ type CreateAutoTranslateCollectionHookOptions = {
3
+ /**
4
+ * The collection's slug. Used to populate the workflow's
5
+ * `collection` input so the queued task targets the right entity.
6
+ */
7
+ collectionSlug: string;
8
+ /**
9
+ * Source-of-truth locale. The hook only fires when the request
10
+ * is operating **in** this locale — edits to a non-default locale
11
+ * don't fan out (those edits would be translations of translations).
12
+ *
13
+ * Falls back to `req.payload.config.localization.defaultLocale`
14
+ * at request time when omitted.
15
+ */
16
+ defaultLocale?: string;
17
+ /**
18
+ * Target locales the workflow fans out to. Defaults to every
19
+ * locale declared on `req.payload.config.localization.locales`
20
+ * **except** the default locale.
21
+ */
22
+ targetLocales?: string[];
23
+ /**
24
+ * Only fan out when the doc is published. Default: `true`.
25
+ * Keeps draft autosaves from triggering per-locale jobs.
26
+ * Set `false` if your host treats drafts as valid translation
27
+ * sources.
28
+ */
29
+ onlyOnPublished?: boolean;
30
+ /**
31
+ * Workflow slug the hook queues. Must match the slug of the
32
+ * workflow registered in
33
+ * `payload.config.ts → jobs: { workflows: [...] }`.
34
+ * Default: `'translateEntityToLocales'`.
35
+ */
36
+ workflowSlug?: string;
37
+ /**
38
+ * Resolver key the queued task should call. Must match a `key`
39
+ * declared in `translator({ resolvers: [...] })`. Default: the
40
+ * first registered resolver's key (resolved at request time),
41
+ * which the workflow forwards to the per-locale task as the
42
+ * `resolver` input.
43
+ */
44
+ resolverKey?: string;
45
+ };
46
+ /**
47
+ * Build a `CollectionAfterChangeHook` that schedules the
48
+ * auto-translation workflow for every non-default locale.
49
+ *
50
+ * Skip rules (any one is sufficient):
51
+ *
52
+ * - `context.disableAutoTranslate` is set (lets seed scripts and
53
+ * tests opt out).
54
+ * - `req.locale` is missing or doesn't match `defaultLocale`.
55
+ * - `req.user` is missing (system-initiated changes shouldn't
56
+ * kick off LLM-billed jobs).
57
+ * - `onlyOnPublished` (default `true`) is enabled and the doc's
58
+ * `_status` is not `'published'`.
59
+ * - The resolved target locale list is empty (e.g. single-locale
60
+ * site).
61
+ */
62
+ declare function createAutoTranslateCollectionHook(options: CreateAutoTranslateCollectionHookOptions): {
63
+ afterChange: CollectionAfterChangeHook;
64
+ };
65
+ import { GlobalAfterChangeHook } from "payload";
66
+ type CreateAutoTranslateGlobalHookOptions = {
67
+ /**
68
+ * The global's slug. Used to populate the workflow's `global`
69
+ * input so the queued task targets the right entity.
70
+ */
71
+ globalSlug: string;
72
+ /**
73
+ * Source-of-truth locale. The hook only fires when the request
74
+ * is operating **in** this locale — edits to a non-default locale
75
+ * don't fan out (those edits would be translations of translations).
76
+ *
77
+ * Falls back to `req.payload.config.localization.defaultLocale`
78
+ * at request time when omitted.
79
+ */
80
+ defaultLocale?: string;
81
+ /**
82
+ * Target locales the workflow fans out to. Defaults to every
83
+ * locale declared on `req.payload.config.localization.locales`
84
+ * **except** the default locale.
85
+ */
86
+ targetLocales?: string[];
87
+ /**
88
+ * Workflow slug the hook queues. Must match the slug of the
89
+ * workflow registered in
90
+ * `payload.config.ts → jobs: { workflows: [...] }`.
91
+ * Default: `'translateEntityToLocales'`.
92
+ */
93
+ workflowSlug?: string;
94
+ /**
95
+ * Resolver key the queued task should call. Must match a `key`
96
+ * declared in `translator({ resolvers: [...] })`. Default: the
97
+ * first registered resolver's key (resolved at request time),
98
+ * which the workflow forwards to the per-locale task as the
99
+ * `resolver` input.
100
+ */
101
+ resolverKey?: string;
102
+ };
103
+ /**
104
+ * Build a `GlobalAfterChangeHook` that schedules the
105
+ * auto-translation workflow for every non-default locale.
106
+ *
107
+ * Same skip rules as the collection hook factory **minus** the
108
+ * `_status === 'published'` check (globals have no versioning —
109
+ * every save is the canonical state). See
110
+ * `createAutoTranslateCollectionHook` for the full rule list.
111
+ */
112
+ declare function createAutoTranslateGlobalHook(options: CreateAutoTranslateGlobalHookOptions): GlobalAfterChangeHook;
113
+ import { TaskConfig, TaskHandler } from "payload";
114
+ type TranslateTaskConfig = Omit<TaskConfig, "handler"> & {
115
+ handler: TaskHandler<string, string>;
116
+ };
117
+ type CreateTranslateTaskOptions = {
118
+ /**
119
+ * Resolver key the upstream `translateOperation` should call.
120
+ * Must match a `key` declared in the host's
121
+ * `translator({ resolvers: [{ key: '<X>', resolve: ... }] })`.
122
+ * Falls back to the first registered resolver's key when omitted.
123
+ */
124
+ resolverKey?: string;
125
+ /**
126
+ * Override the task slug. Default:
127
+ * `'translateEntityToLocale'`.
128
+ */
129
+ slug?: string;
130
+ };
131
+ /**
132
+ * Build the per-locale translation task.
133
+ *
134
+ * Behaviour:
135
+ *
136
+ * 1. Call `translateOperation` with
137
+ * `emptyOnly: false, overrideAccess: true, update: false` so we
138
+ * get a translated payload without the plugin writing back.
139
+ * 2. Strip the synthetic `_locale` / `_parent_id` keys the plugin
140
+ * attaches to the result.
141
+ * 3. Persist via `req.payload.update` (collection) or
142
+ * `req.payload.updateGlobal` (global) at `toLocale`, again with
143
+ * `overrideAccess: true` so jobs run cleanly outside user
144
+ * sessions.
145
+ * 4. Fail loudly on any error — Payload retries the task up to
146
+ * `retries` times before giving up.
147
+ *
148
+ * Hosts wire the returned task into
149
+ * `payload.config.ts → jobs: { tasks: [<task>] }`.
150
+ */
151
+ declare function createTranslateTask(options?: CreateTranslateTaskOptions): TranslateTaskConfig;
152
+ import { WorkflowConfig, WorkflowHandler } from "payload";
153
+ type TranslateWorkflowConfig = Omit<WorkflowConfig, "handler"> & {
154
+ handler: WorkflowHandler;
155
+ };
156
+ type CreateTranslateWorkflowOptions = {
157
+ /**
158
+ * Override the workflow slug. Default:
159
+ * `'translateEntityToLocales'`.
160
+ */
161
+ slug?: string;
162
+ /**
163
+ * Override the per-locale task slug the workflow schedules.
164
+ * Must match the slug passed to `createTranslateTask` on the
165
+ * host's side. Default: `'translateEntityToLocale'`.
166
+ */
167
+ taskSlug?: string;
168
+ };
169
+ /**
170
+ * Build the per-save translation workflow.
171
+ *
172
+ * The workflow receives one `entity + (fromLocale, toLocale, updatedAt)`
173
+ * tuple per call and schedules **one** `translateEntityToLocale` task.
174
+ * The `afterChange` hook factories fan out one call per non-default
175
+ * locale so each task runs independently — one failing locale does
176
+ * not block the others.
177
+ *
178
+ * The dedupe key (entity + locales + `updatedAt`) lets Payload collapse
179
+ * duplicate jobs queued by rapid autosave bursts.
180
+ *
181
+ * Hosts wire the returned workflow into
182
+ * `payload.config.ts → jobs: { workflows: [<workflow>] }`.
183
+ */
184
+ declare function createTranslateWorkflow(options?: CreateTranslateWorkflowOptions): TranslateWorkflowConfig;
185
+ declare const TRANSLATE_TASK_SLUG = "translateEntityToLocale";
186
+ declare const TRANSLATE_WORKFLOW_SLUG = "translateEntityToLocales";
187
+ declare const jobs: {
188
+ TRANSLATE_TASK_SLUG: string;
189
+ TRANSLATE_WORKFLOW_SLUG: string;
190
+ createTranslateTask: typeof createTranslateTask;
191
+ createTranslateWorkflow: typeof createTranslateWorkflow;
192
+ createAutoTranslateCollectionHook: typeof createAutoTranslateCollectionHook;
193
+ createAutoTranslateGlobalHook: typeof createAutoTranslateGlobalHook;
194
+ };
195
+ export { jobs as default, createTranslateWorkflow, createTranslateTask, createAutoTranslateGlobalHook, createAutoTranslateCollectionHook, TranslateWorkflowConfig, TranslateTaskConfig, TRANSLATE_WORKFLOW_SLUG, TRANSLATE_TASK_SLUG, CreateTranslateWorkflowOptions, CreateTranslateTaskOptions, CreateAutoTranslateGlobalHookOptions, CreateAutoTranslateCollectionHookOptions };