@fonderie/react-courier-admin 0.2.0 → 0.4.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/index.cjs +63 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -19
- package/dist/index.d.ts +12 -19
- package/dist/index.js +59 -82
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -20,115 +20,63 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
CourierAdminClient: () =>
|
|
24
|
-
FonderieApiError: () =>
|
|
25
|
-
useDeleteTemplate: () => useDeleteTemplate,
|
|
26
|
-
useSaveTemplate: () => useSaveTemplate,
|
|
23
|
+
CourierAdminClient: () => import_client5.CourierAdminClient,
|
|
24
|
+
FonderieApiError: () => import_client5.FonderieApiError,
|
|
27
25
|
useTemplate: () => useTemplate,
|
|
26
|
+
useTemplatePreview: () => useTemplatePreview,
|
|
28
27
|
useTemplateRevisions: () => useTemplateRevisions,
|
|
29
28
|
useTemplates: () => useTemplates
|
|
30
29
|
});
|
|
31
30
|
module.exports = __toCommonJS(index_exports);
|
|
32
|
-
var
|
|
31
|
+
var import_client5 = require("@fonderie/client");
|
|
33
32
|
|
|
34
|
-
// src/hooks/
|
|
33
|
+
// src/hooks/useTemplate.ts
|
|
35
34
|
var import_client = require("@fonderie/client");
|
|
36
35
|
var import_react = require("react");
|
|
37
|
-
function useDeleteTemplate(client) {
|
|
38
|
-
const [isLoading, setIsLoading] = (0, import_react.useState)(false);
|
|
39
|
-
const [error, setError] = (0, import_react.useState)(null);
|
|
40
|
-
const deleteTemplate = (0, import_react.useCallback)(
|
|
41
|
-
async (type, locale) => {
|
|
42
|
-
setIsLoading(true);
|
|
43
|
-
setError(null);
|
|
44
|
-
try {
|
|
45
|
-
await client.deleteTemplate(type, locale);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
const apiError = err instanceof import_client.FonderieApiError ? err : new import_client.FonderieApiError("unknown", String(err), 0);
|
|
48
|
-
setError(apiError);
|
|
49
|
-
throw apiError;
|
|
50
|
-
} finally {
|
|
51
|
-
setIsLoading(false);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
[client]
|
|
55
|
-
);
|
|
56
|
-
return { deleteTemplate, isLoading, error };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/hooks/useSaveTemplate.ts
|
|
60
|
-
var import_client2 = require("@fonderie/client");
|
|
61
|
-
var import_react2 = require("react");
|
|
62
|
-
function useSaveTemplate(client) {
|
|
63
|
-
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
64
|
-
const [error, setError] = (0, import_react2.useState)(null);
|
|
65
|
-
const saveTemplate = (0, import_react2.useCallback)(
|
|
66
|
-
async (type, input, locale) => {
|
|
67
|
-
setIsLoading(true);
|
|
68
|
-
setError(null);
|
|
69
|
-
try {
|
|
70
|
-
const { result } = await client.setTemplate(type, input, locale);
|
|
71
|
-
return result;
|
|
72
|
-
} catch (err) {
|
|
73
|
-
const apiError = err instanceof import_client2.FonderieApiError ? err : new import_client2.FonderieApiError("unknown", String(err), 0);
|
|
74
|
-
setError(apiError);
|
|
75
|
-
throw apiError;
|
|
76
|
-
} finally {
|
|
77
|
-
setIsLoading(false);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
[client]
|
|
81
|
-
);
|
|
82
|
-
return { saveTemplate, isLoading, error };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/hooks/useTemplate.ts
|
|
86
|
-
var import_client3 = require("@fonderie/client");
|
|
87
|
-
var import_react3 = require("react");
|
|
88
36
|
function useTemplate(client, type, locale) {
|
|
89
|
-
const [template, setTemplate] = (0,
|
|
90
|
-
const [isLoading, setIsLoading] = (0,
|
|
91
|
-
const [error, setError] = (0,
|
|
92
|
-
const refresh = (0,
|
|
37
|
+
const [template, setTemplate] = (0, import_react.useState)(null);
|
|
38
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
39
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
40
|
+
const refresh = (0, import_react.useCallback)(async () => {
|
|
93
41
|
setIsLoading(true);
|
|
94
42
|
setError(null);
|
|
95
43
|
try {
|
|
96
44
|
const { result } = await client.getTemplate(type, locale);
|
|
97
45
|
setTemplate(result);
|
|
98
46
|
} catch (err) {
|
|
99
|
-
const apiError = err instanceof
|
|
47
|
+
const apiError = err instanceof import_client.FonderieApiError ? err : new import_client.FonderieApiError("unknown", String(err), 0);
|
|
100
48
|
setError(apiError);
|
|
101
49
|
} finally {
|
|
102
50
|
setIsLoading(false);
|
|
103
51
|
}
|
|
104
52
|
}, [client, type, locale]);
|
|
105
|
-
(0,
|
|
53
|
+
(0, import_react.useEffect)(() => {
|
|
106
54
|
void refresh();
|
|
107
55
|
}, [refresh]);
|
|
108
56
|
return { template, isLoading, error, refresh };
|
|
109
57
|
}
|
|
110
58
|
|
|
111
59
|
// src/hooks/useTemplateRevisions.ts
|
|
112
|
-
var
|
|
113
|
-
var
|
|
60
|
+
var import_client2 = require("@fonderie/client");
|
|
61
|
+
var import_react2 = require("react");
|
|
114
62
|
function useTemplateRevisions(client, type, locale) {
|
|
115
|
-
const [revisions, setRevisions] = (0,
|
|
116
|
-
const [isLoading, setIsLoading] = (0,
|
|
117
|
-
const [error, setError] = (0,
|
|
118
|
-
const refresh = (0,
|
|
63
|
+
const [revisions, setRevisions] = (0, import_react2.useState)([]);
|
|
64
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
65
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
66
|
+
const refresh = (0, import_react2.useCallback)(async () => {
|
|
119
67
|
setIsLoading(true);
|
|
120
68
|
setError(null);
|
|
121
69
|
try {
|
|
122
70
|
const { result } = await client.listRevisions(type, locale);
|
|
123
71
|
setRevisions(result);
|
|
124
72
|
} catch (err) {
|
|
125
|
-
const apiError = err instanceof
|
|
73
|
+
const apiError = err instanceof import_client2.FonderieApiError ? err : new import_client2.FonderieApiError("unknown", String(err), 0);
|
|
126
74
|
setError(apiError);
|
|
127
75
|
} finally {
|
|
128
76
|
setIsLoading(false);
|
|
129
77
|
}
|
|
130
78
|
}, [client, type, locale]);
|
|
131
|
-
const rollback = (0,
|
|
79
|
+
const rollback = (0, import_react2.useCallback)(
|
|
132
80
|
async (toVersion) => {
|
|
133
81
|
setError(null);
|
|
134
82
|
try {
|
|
@@ -136,40 +84,40 @@ function useTemplateRevisions(client, type, locale) {
|
|
|
136
84
|
await refresh();
|
|
137
85
|
return result;
|
|
138
86
|
} catch (err) {
|
|
139
|
-
const apiError = err instanceof
|
|
87
|
+
const apiError = err instanceof import_client2.FonderieApiError ? err : new import_client2.FonderieApiError("unknown", String(err), 0);
|
|
140
88
|
setError(apiError);
|
|
141
89
|
throw apiError;
|
|
142
90
|
}
|
|
143
91
|
},
|
|
144
92
|
[client, type, locale, refresh]
|
|
145
93
|
);
|
|
146
|
-
(0,
|
|
94
|
+
(0, import_react2.useEffect)(() => {
|
|
147
95
|
void refresh();
|
|
148
96
|
}, [refresh]);
|
|
149
97
|
return { revisions, isLoading, error, refresh, rollback };
|
|
150
98
|
}
|
|
151
99
|
|
|
152
100
|
// src/hooks/useTemplates.ts
|
|
153
|
-
var
|
|
154
|
-
var
|
|
101
|
+
var import_client3 = require("@fonderie/client");
|
|
102
|
+
var import_react3 = require("react");
|
|
155
103
|
function useTemplates(client) {
|
|
156
|
-
const [templates, setTemplates] = (0,
|
|
157
|
-
const [isLoading, setIsLoading] = (0,
|
|
158
|
-
const [error, setError] = (0,
|
|
159
|
-
const refresh = (0,
|
|
104
|
+
const [templates, setTemplates] = (0, import_react3.useState)([]);
|
|
105
|
+
const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
|
|
106
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
107
|
+
const refresh = (0, import_react3.useCallback)(async () => {
|
|
160
108
|
setIsLoading(true);
|
|
161
109
|
setError(null);
|
|
162
110
|
try {
|
|
163
111
|
const { result } = await client.listTemplates();
|
|
164
112
|
setTemplates(result);
|
|
165
113
|
} catch (err) {
|
|
166
|
-
const apiError = err instanceof
|
|
114
|
+
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
167
115
|
setError(apiError);
|
|
168
116
|
} finally {
|
|
169
117
|
setIsLoading(false);
|
|
170
118
|
}
|
|
171
119
|
}, [client]);
|
|
172
|
-
const saveTemplate = (0,
|
|
120
|
+
const saveTemplate = (0, import_react3.useCallback)(
|
|
173
121
|
async (type, input, locale) => {
|
|
174
122
|
setError(null);
|
|
175
123
|
try {
|
|
@@ -177,39 +125,67 @@ function useTemplates(client) {
|
|
|
177
125
|
await refresh();
|
|
178
126
|
return result;
|
|
179
127
|
} catch (err) {
|
|
180
|
-
const apiError = err instanceof
|
|
128
|
+
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
181
129
|
setError(apiError);
|
|
182
130
|
throw apiError;
|
|
183
131
|
}
|
|
184
132
|
},
|
|
185
133
|
[client, refresh]
|
|
186
134
|
);
|
|
187
|
-
const removeTemplate = (0,
|
|
135
|
+
const removeTemplate = (0, import_react3.useCallback)(
|
|
188
136
|
async (type, locale) => {
|
|
189
137
|
setError(null);
|
|
190
138
|
try {
|
|
191
139
|
await client.deleteTemplate(type, locale);
|
|
192
140
|
await refresh();
|
|
193
141
|
} catch (err) {
|
|
194
|
-
const apiError = err instanceof
|
|
142
|
+
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
195
143
|
setError(apiError);
|
|
196
144
|
throw apiError;
|
|
197
145
|
}
|
|
198
146
|
},
|
|
199
147
|
[client, refresh]
|
|
200
148
|
);
|
|
201
|
-
(0,
|
|
149
|
+
(0, import_react3.useEffect)(() => {
|
|
202
150
|
void refresh();
|
|
203
151
|
}, [refresh]);
|
|
204
152
|
return { templates, isLoading, error, refresh, saveTemplate, removeTemplate };
|
|
205
153
|
}
|
|
154
|
+
|
|
155
|
+
// src/hooks/useTemplatePreview.ts
|
|
156
|
+
var import_client4 = require("@fonderie/client");
|
|
157
|
+
var import_react4 = require("react");
|
|
158
|
+
function useTemplatePreview(client) {
|
|
159
|
+
const [preview, setPreview] = (0, import_react4.useState)(null);
|
|
160
|
+
const [isPreviewing, setIsPreviewing] = (0, import_react4.useState)(false);
|
|
161
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
162
|
+
const renderPreview = (0, import_react4.useCallback)(
|
|
163
|
+
async (type, input, locale) => {
|
|
164
|
+
setIsPreviewing(true);
|
|
165
|
+
setError(null);
|
|
166
|
+
try {
|
|
167
|
+
const { result } = await client.previewTemplate(type, input, locale);
|
|
168
|
+
setPreview(result);
|
|
169
|
+
return result;
|
|
170
|
+
} catch (err) {
|
|
171
|
+
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
172
|
+
setError(apiError);
|
|
173
|
+
throw apiError;
|
|
174
|
+
} finally {
|
|
175
|
+
setIsPreviewing(false);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
[client]
|
|
179
|
+
);
|
|
180
|
+
const clearPreview = (0, import_react4.useCallback)(() => setPreview(null), []);
|
|
181
|
+
return { preview, isPreviewing, error, renderPreview, clearPreview };
|
|
182
|
+
}
|
|
206
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
207
184
|
0 && (module.exports = {
|
|
208
185
|
CourierAdminClient,
|
|
209
186
|
FonderieApiError,
|
|
210
|
-
useDeleteTemplate,
|
|
211
|
-
useSaveTemplate,
|
|
212
187
|
useTemplate,
|
|
188
|
+
useTemplatePreview,
|
|
213
189
|
useTemplateRevisions,
|
|
214
190
|
useTemplates
|
|
215
191
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useDeleteTemplate.ts","../src/hooks/useSaveTemplate.ts","../src/hooks/useTemplate.ts","../src/hooks/useTemplateRevisions.ts","../src/hooks/useTemplates.ts"],"sourcesContent":["export type {\n\tICourierAdminClientOptions,\n\tIRollbackTemplateInput,\n\tISetTemplateInput,\n\tITemplateEntry,\n\tITemplateRevision,\n} from '@fonderie/client';\nexport { CourierAdminClient, FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseDeleteTemplateReturn,\n\tIUseSaveTemplateReturn,\n\tIUseTemplateReturn,\n\tIUseTemplateRevisionsReturn,\n\tIUseTemplatesReturn,\n} from './hooks';\nexport {\n\tuseDeleteTemplate,\n\tuseSaveTemplate,\n\tuseTemplate,\n\tuseTemplateRevisions,\n\tuseTemplates,\n} from './hooks';\n","import type { CourierAdminClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseDeleteTemplateReturn {\n\tdeleteTemplate: (type: string, locale?: string | null) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n/** @deprecated Use `useTemplates().removeTemplate` instead — it refreshes the list after deleting. */\nexport function useDeleteTemplate(client: CourierAdminClient): IUseDeleteTemplateReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst deleteTemplate = useCallback(\n\t\tasync (type: string, locale?: string | null) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deleteTemplate(type, locale);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { deleteTemplate, isLoading, error };\n}\n","import type { CourierAdminClient, ISetTemplateInput, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseSaveTemplateReturn {\n\tsaveTemplate: (\n\t\ttype: string,\n\t\tinput: ISetTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<ITemplateEntry>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n/** @deprecated Use `useTemplates().saveTemplate` instead — it refreshes the list after saving. */\nexport function useSaveTemplate(client: CourierAdminClient): IUseSaveTemplateReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst saveTemplate = useCallback(\n\t\tasync (type: string, input: ISetTemplateInput, locale?: string | null) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.setTemplate(type, input, locale);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { saveTemplate, isLoading, error };\n}\n","import type { CourierAdminClient, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateReturn {\n\ttemplate: ITemplateEntry | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function useTemplate(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateReturn {\n\tconst [template, setTemplate] = useState<ITemplateEntry | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getTemplate(type, locale);\n\t\t\tsetTemplate(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { template, isLoading, error, refresh };\n}\n","import type { CourierAdminClient, ITemplateEntry, ITemplateRevision } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateRevisionsReturn {\n\trevisions: ITemplateRevision[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\trollback: (toVersion: number) => Promise<ITemplateEntry>;\n}\n\nexport function useTemplateRevisions(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateRevisionsReturn {\n\tconst [revisions, setRevisions] = useState<ITemplateRevision[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listRevisions(type, locale);\n\t\t\tsetRevisions(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tconst rollback = useCallback(\n\t\tasync (toVersion: number) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.rollback(type, { toVersion }, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, type, locale, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { revisions, isLoading, error, refresh, rollback };\n}\n","import type { CourierAdminClient, ISetTemplateInput, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplatesReturn {\n\ttemplates: ITemplateEntry[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\tsaveTemplate: (\n\t\ttype: string,\n\t\tinput: ISetTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<ITemplateEntry>;\n\tremoveTemplate: (type: string, locale?: string | null) => Promise<void>;\n}\n\nexport function useTemplates(client: CourierAdminClient): IUseTemplatesReturn {\n\tconst [templates, setTemplates] = useState<ITemplateEntry[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listTemplates();\n\t\t\tsetTemplates(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tconst saveTemplate = useCallback(\n\t\tasync (type: string, input: ISetTemplateInput, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.setTemplate(type, input, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tconst removeTemplate = useCallback(\n\t\tasync (type: string, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deleteTemplate(type, locale);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { templates, isLoading, error, refresh, saveTemplate, removeTemplate };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,IAAAA,iBAAqD;;;ACNrD,oBAAiC;AACjC,mBAAsC;AAS/B,SAAS,kBAAkB,QAAsD;AACvF,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAkC,IAAI;AAEhE,QAAM,qBAAiB;AAAA,IACtB,OAAO,MAAc,WAA2B;AAC/C,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,OAAO,eAAe,MAAM,MAAM;AAAA,MACzC,SAAS,KAAK;AACb,cAAM,WACL,eAAe,iCAAmB,MAAM,IAAI,+BAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,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OAAO,eAAe,MAAM,MAAM;AACxC,cAAM,QAAQ;AAAA,MACf,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,OAAO;AAAA,EACjB;AAEA,+BAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,WAAW,WAAW,OAAO,SAAS,cAAc,eAAe;AAC7E;","names":["import_client","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/useTemplate.ts","../src/hooks/useTemplateRevisions.ts","../src/hooks/useTemplates.ts","../src/hooks/useTemplatePreview.ts"],"sourcesContent":["export type {\n\tICourierAdminClientOptions,\n\tIPreviewTemplateInput,\n\tIRenderedTemplateResult,\n\tIRollbackTemplateInput,\n\tISetTemplateInput,\n\tITemplateEntry,\n\tITemplateRevision,\n} from '@fonderie/client';\nexport { CourierAdminClient, FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseTemplatePreviewReturn,\n\tIUseTemplateReturn,\n\tIUseTemplateRevisionsReturn,\n\tIUseTemplatesReturn,\n} from './hooks';\nexport {\n\tuseTemplate,\n\tuseTemplatePreview,\n\tuseTemplateRevisions,\n\tuseTemplates,\n} from './hooks';\n","import type { CourierAdminClient, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateReturn {\n\ttemplate: ITemplateEntry | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function useTemplate(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateReturn {\n\tconst [template, setTemplate] = useState<ITemplateEntry | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getTemplate(type, locale);\n\t\t\tsetTemplate(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { template, isLoading, error, refresh };\n}\n","import type { CourierAdminClient, ITemplateEntry, ITemplateRevision } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateRevisionsReturn {\n\trevisions: ITemplateRevision[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\trollback: (toVersion: number) => Promise<ITemplateEntry>;\n}\n\nexport function useTemplateRevisions(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateRevisionsReturn {\n\tconst [revisions, setRevisions] = useState<ITemplateRevision[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listRevisions(type, locale);\n\t\t\tsetRevisions(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tconst rollback = useCallback(\n\t\tasync (toVersion: number) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.rollback(type, { toVersion }, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, type, locale, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { revisions, isLoading, error, refresh, rollback };\n}\n","import type { CourierAdminClient, ISetTemplateInput, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplatesReturn {\n\ttemplates: ITemplateEntry[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\tsaveTemplate: (\n\t\ttype: string,\n\t\tinput: ISetTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<ITemplateEntry>;\n\tremoveTemplate: (type: string, locale?: string | null) => Promise<void>;\n}\n\nexport function useTemplates(client: CourierAdminClient): IUseTemplatesReturn {\n\tconst [templates, setTemplates] = useState<ITemplateEntry[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listTemplates();\n\t\t\tsetTemplates(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tconst saveTemplate = useCallback(\n\t\tasync (type: string, input: ISetTemplateInput, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.setTemplate(type, input, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tconst removeTemplate = useCallback(\n\t\tasync (type: string, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deleteTemplate(type, locale);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { templates, isLoading, error, refresh, saveTemplate, removeTemplate };\n}\n","import type {\n\tCourierAdminClient,\n\tIPreviewTemplateInput,\n\tIRenderedTemplateResult,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseTemplatePreviewReturn {\n\tpreview: IRenderedTemplateResult | null;\n\tisPreviewing: boolean;\n\terror: FonderieApiError | null;\n\trenderPreview: (\n\t\ttype: string,\n\t\tinput: IPreviewTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<IRenderedTemplateResult>;\n\tclearPreview: () => void;\n}\n\n// On demand, not on mount: the caller decides when the editor's content is\n// worth rendering. Server-side, so what comes back is what the resolver\n// produces — the layout shell and the variable substitution included.\nexport function useTemplatePreview(client: CourierAdminClient): IUseTemplatePreviewReturn {\n\tconst [preview, setPreview] = useState<IRenderedTemplateResult | null>(null);\n\tconst [isPreviewing, setIsPreviewing] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst renderPreview = useCallback(\n\t\tasync (type: string, input: IPreviewTemplateInput, locale?: string | null) => {\n\t\t\tsetIsPreviewing(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.previewTemplate(type, input, locale);\n\t\t\t\tsetPreview(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsPreviewing(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\tconst clearPreview = useCallback(() => setPreview(null), []);\n\n\treturn { preview, isPreviewing, error, renderPreview, clearPreview };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,IAAAA,iBAAqD;;;ACRrD,oBAAiC;AACjC,mBAAiD;AAS1C,SAAS,YACf,QACA,MACA,QACqB;AACrB,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAgC,IAAI;AACpE,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAkC,IAAI;AAEhE,QAAM,cAAU,0BAAY,YAAY;AACvC,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,YAAY,MAAM,MAAM;AACxD,kBAAY,MAAM;AAAA,IACnB,SAAS,KAAK;AACb,YAAM,WACL,eAAe,iCAAmB,MAAM,IAAI,+BAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,eAAS,QAAQ;AAAA,IAClB,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,QAAQ,MAAM,MAAM,CAAC;AA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AAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,OAAO;AAAA,EACjB;AAEA,+BAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,WAAW,WAAW,OAAO,SAAS,cAAc,eAAe;AAC7E;;;ACtEA,IAAAC,iBAAiC;AACjC,IAAAC,gBAAsC;AAiB/B,SAAS,mBAAmB,QAAuD;AACzF,QAAM,CAAC,SAAS,UAAU,QAAI,wBAAyC,IAAI;AAC3E,QAAM,CAAC,cAAc,eAAe,QAAI,wBAAS,KAAK;AACtD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,IAAI;AAEhE,QAAM,oBAAgB;AAAA,IACrB,OAAO,MAAc,OAA8B,WAA2B;AAC7E,sBAAgB,IAAI;AACpB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,OAAO,gBAAgB,MAAM,OAAO,MAAM;AACnE,mBAAW,MAAM;AACjB,eAAO;AAAA,MACR,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,wBAAgB,KAAK;AAAA,MACtB;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAEA,QAAM,mBAAe,2BAAY,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAE3D,SAAO,EAAE,SAAS,cAAc,OAAO,eAAe,aAAa;AACpE;","names":["import_client","import_client","import_react","import_client","import_react","import_client","import_react"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import { FonderieApiError, CourierAdminClient, ISetTemplateInput,
|
|
2
|
-
export { CourierAdminClient, FonderieApiError, ICourierAdminClientOptions, IRollbackTemplateInput, ISetTemplateInput, ITemplateEntry, ITemplateRevision } from '@fonderie/client';
|
|
3
|
-
|
|
4
|
-
interface IUseDeleteTemplateReturn {
|
|
5
|
-
deleteTemplate: (type: string, locale?: string | null) => Promise<void>;
|
|
6
|
-
isLoading: boolean;
|
|
7
|
-
error: FonderieApiError | null;
|
|
8
|
-
}
|
|
9
|
-
/** @deprecated Use `useTemplates().removeTemplate` instead — it refreshes the list after deleting. */
|
|
10
|
-
declare function useDeleteTemplate(client: CourierAdminClient): IUseDeleteTemplateReturn;
|
|
11
|
-
|
|
12
|
-
interface IUseSaveTemplateReturn {
|
|
13
|
-
saveTemplate: (type: string, input: ISetTemplateInput, locale?: string | null) => Promise<ITemplateEntry>;
|
|
14
|
-
isLoading: boolean;
|
|
15
|
-
error: FonderieApiError | null;
|
|
16
|
-
}
|
|
17
|
-
/** @deprecated Use `useTemplates().saveTemplate` instead — it refreshes the list after saving. */
|
|
18
|
-
declare function useSaveTemplate(client: CourierAdminClient): IUseSaveTemplateReturn;
|
|
1
|
+
import { ITemplateEntry, FonderieApiError, CourierAdminClient, ITemplateRevision, ISetTemplateInput, IRenderedTemplateResult, IPreviewTemplateInput } from '@fonderie/client';
|
|
2
|
+
export { CourierAdminClient, FonderieApiError, ICourierAdminClientOptions, IPreviewTemplateInput, IRenderedTemplateResult, IRollbackTemplateInput, ISetTemplateInput, ITemplateEntry, ITemplateRevision } from '@fonderie/client';
|
|
19
3
|
|
|
20
4
|
interface IUseTemplateReturn {
|
|
21
5
|
template: ITemplateEntry | null;
|
|
@@ -44,4 +28,13 @@ interface IUseTemplatesReturn {
|
|
|
44
28
|
}
|
|
45
29
|
declare function useTemplates(client: CourierAdminClient): IUseTemplatesReturn;
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
interface IUseTemplatePreviewReturn {
|
|
32
|
+
preview: IRenderedTemplateResult | null;
|
|
33
|
+
isPreviewing: boolean;
|
|
34
|
+
error: FonderieApiError | null;
|
|
35
|
+
renderPreview: (type: string, input: IPreviewTemplateInput, locale?: string | null) => Promise<IRenderedTemplateResult>;
|
|
36
|
+
clearPreview: () => void;
|
|
37
|
+
}
|
|
38
|
+
declare function useTemplatePreview(client: CourierAdminClient): IUseTemplatePreviewReturn;
|
|
39
|
+
|
|
40
|
+
export { type IUseTemplatePreviewReturn, type IUseTemplateReturn, type IUseTemplateRevisionsReturn, type IUseTemplatesReturn, useTemplate, useTemplatePreview, useTemplateRevisions, useTemplates };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import { FonderieApiError, CourierAdminClient, ISetTemplateInput,
|
|
2
|
-
export { CourierAdminClient, FonderieApiError, ICourierAdminClientOptions, IRollbackTemplateInput, ISetTemplateInput, ITemplateEntry, ITemplateRevision } from '@fonderie/client';
|
|
3
|
-
|
|
4
|
-
interface IUseDeleteTemplateReturn {
|
|
5
|
-
deleteTemplate: (type: string, locale?: string | null) => Promise<void>;
|
|
6
|
-
isLoading: boolean;
|
|
7
|
-
error: FonderieApiError | null;
|
|
8
|
-
}
|
|
9
|
-
/** @deprecated Use `useTemplates().removeTemplate` instead — it refreshes the list after deleting. */
|
|
10
|
-
declare function useDeleteTemplate(client: CourierAdminClient): IUseDeleteTemplateReturn;
|
|
11
|
-
|
|
12
|
-
interface IUseSaveTemplateReturn {
|
|
13
|
-
saveTemplate: (type: string, input: ISetTemplateInput, locale?: string | null) => Promise<ITemplateEntry>;
|
|
14
|
-
isLoading: boolean;
|
|
15
|
-
error: FonderieApiError | null;
|
|
16
|
-
}
|
|
17
|
-
/** @deprecated Use `useTemplates().saveTemplate` instead — it refreshes the list after saving. */
|
|
18
|
-
declare function useSaveTemplate(client: CourierAdminClient): IUseSaveTemplateReturn;
|
|
1
|
+
import { ITemplateEntry, FonderieApiError, CourierAdminClient, ITemplateRevision, ISetTemplateInput, IRenderedTemplateResult, IPreviewTemplateInput } from '@fonderie/client';
|
|
2
|
+
export { CourierAdminClient, FonderieApiError, ICourierAdminClientOptions, IPreviewTemplateInput, IRenderedTemplateResult, IRollbackTemplateInput, ISetTemplateInput, ITemplateEntry, ITemplateRevision } from '@fonderie/client';
|
|
19
3
|
|
|
20
4
|
interface IUseTemplateReturn {
|
|
21
5
|
template: ITemplateEntry | null;
|
|
@@ -44,4 +28,13 @@ interface IUseTemplatesReturn {
|
|
|
44
28
|
}
|
|
45
29
|
declare function useTemplates(client: CourierAdminClient): IUseTemplatesReturn;
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
interface IUseTemplatePreviewReturn {
|
|
32
|
+
preview: IRenderedTemplateResult | null;
|
|
33
|
+
isPreviewing: boolean;
|
|
34
|
+
error: FonderieApiError | null;
|
|
35
|
+
renderPreview: (type: string, input: IPreviewTemplateInput, locale?: string | null) => Promise<IRenderedTemplateResult>;
|
|
36
|
+
clearPreview: () => void;
|
|
37
|
+
}
|
|
38
|
+
declare function useTemplatePreview(client: CourierAdminClient): IUseTemplatePreviewReturn;
|
|
39
|
+
|
|
40
|
+
export { type IUseTemplatePreviewReturn, type IUseTemplateReturn, type IUseTemplateRevisionsReturn, type IUseTemplatesReturn, useTemplate, useTemplatePreview, useTemplateRevisions, useTemplates };
|
package/dist/index.js
CHANGED
|
@@ -1,72 +1,21 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { CourierAdminClient, FonderieApiError as
|
|
3
|
-
|
|
4
|
-
// src/hooks/useDeleteTemplate.ts
|
|
5
|
-
import { FonderieApiError } from "@fonderie/client";
|
|
6
|
-
import { useCallback, useState } from "react";
|
|
7
|
-
function useDeleteTemplate(client) {
|
|
8
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
9
|
-
const [error, setError] = useState(null);
|
|
10
|
-
const deleteTemplate = useCallback(
|
|
11
|
-
async (type, locale) => {
|
|
12
|
-
setIsLoading(true);
|
|
13
|
-
setError(null);
|
|
14
|
-
try {
|
|
15
|
-
await client.deleteTemplate(type, locale);
|
|
16
|
-
} catch (err) {
|
|
17
|
-
const apiError = err instanceof FonderieApiError ? err : new FonderieApiError("unknown", String(err), 0);
|
|
18
|
-
setError(apiError);
|
|
19
|
-
throw apiError;
|
|
20
|
-
} finally {
|
|
21
|
-
setIsLoading(false);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
[client]
|
|
25
|
-
);
|
|
26
|
-
return { deleteTemplate, isLoading, error };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/hooks/useSaveTemplate.ts
|
|
30
|
-
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
31
|
-
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
32
|
-
function useSaveTemplate(client) {
|
|
33
|
-
const [isLoading, setIsLoading] = useState2(false);
|
|
34
|
-
const [error, setError] = useState2(null);
|
|
35
|
-
const saveTemplate = useCallback2(
|
|
36
|
-
async (type, input, locale) => {
|
|
37
|
-
setIsLoading(true);
|
|
38
|
-
setError(null);
|
|
39
|
-
try {
|
|
40
|
-
const { result } = await client.setTemplate(type, input, locale);
|
|
41
|
-
return result;
|
|
42
|
-
} catch (err) {
|
|
43
|
-
const apiError = err instanceof FonderieApiError2 ? err : new FonderieApiError2("unknown", String(err), 0);
|
|
44
|
-
setError(apiError);
|
|
45
|
-
throw apiError;
|
|
46
|
-
} finally {
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
[client]
|
|
51
|
-
);
|
|
52
|
-
return { saveTemplate, isLoading, error };
|
|
53
|
-
}
|
|
2
|
+
import { CourierAdminClient, FonderieApiError as FonderieApiError5 } from "@fonderie/client";
|
|
54
3
|
|
|
55
4
|
// src/hooks/useTemplate.ts
|
|
56
|
-
import { FonderieApiError
|
|
57
|
-
import { useCallback
|
|
5
|
+
import { FonderieApiError } from "@fonderie/client";
|
|
6
|
+
import { useCallback, useEffect, useState } from "react";
|
|
58
7
|
function useTemplate(client, type, locale) {
|
|
59
|
-
const [template, setTemplate] =
|
|
60
|
-
const [isLoading, setIsLoading] =
|
|
61
|
-
const [error, setError] =
|
|
62
|
-
const refresh =
|
|
8
|
+
const [template, setTemplate] = useState(null);
|
|
9
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const refresh = useCallback(async () => {
|
|
63
12
|
setIsLoading(true);
|
|
64
13
|
setError(null);
|
|
65
14
|
try {
|
|
66
15
|
const { result } = await client.getTemplate(type, locale);
|
|
67
16
|
setTemplate(result);
|
|
68
17
|
} catch (err) {
|
|
69
|
-
const apiError = err instanceof
|
|
18
|
+
const apiError = err instanceof FonderieApiError ? err : new FonderieApiError("unknown", String(err), 0);
|
|
70
19
|
setError(apiError);
|
|
71
20
|
} finally {
|
|
72
21
|
setIsLoading(false);
|
|
@@ -79,26 +28,26 @@ function useTemplate(client, type, locale) {
|
|
|
79
28
|
}
|
|
80
29
|
|
|
81
30
|
// src/hooks/useTemplateRevisions.ts
|
|
82
|
-
import { FonderieApiError as
|
|
83
|
-
import { useCallback as
|
|
31
|
+
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
32
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
84
33
|
function useTemplateRevisions(client, type, locale) {
|
|
85
|
-
const [revisions, setRevisions] =
|
|
86
|
-
const [isLoading, setIsLoading] =
|
|
87
|
-
const [error, setError] =
|
|
88
|
-
const refresh =
|
|
34
|
+
const [revisions, setRevisions] = useState2([]);
|
|
35
|
+
const [isLoading, setIsLoading] = useState2(true);
|
|
36
|
+
const [error, setError] = useState2(null);
|
|
37
|
+
const refresh = useCallback2(async () => {
|
|
89
38
|
setIsLoading(true);
|
|
90
39
|
setError(null);
|
|
91
40
|
try {
|
|
92
41
|
const { result } = await client.listRevisions(type, locale);
|
|
93
42
|
setRevisions(result);
|
|
94
43
|
} catch (err) {
|
|
95
|
-
const apiError = err instanceof
|
|
44
|
+
const apiError = err instanceof FonderieApiError2 ? err : new FonderieApiError2("unknown", String(err), 0);
|
|
96
45
|
setError(apiError);
|
|
97
46
|
} finally {
|
|
98
47
|
setIsLoading(false);
|
|
99
48
|
}
|
|
100
49
|
}, [client, type, locale]);
|
|
101
|
-
const rollback =
|
|
50
|
+
const rollback = useCallback2(
|
|
102
51
|
async (toVersion) => {
|
|
103
52
|
setError(null);
|
|
104
53
|
try {
|
|
@@ -106,7 +55,7 @@ function useTemplateRevisions(client, type, locale) {
|
|
|
106
55
|
await refresh();
|
|
107
56
|
return result;
|
|
108
57
|
} catch (err) {
|
|
109
|
-
const apiError = err instanceof
|
|
58
|
+
const apiError = err instanceof FonderieApiError2 ? err : new FonderieApiError2("unknown", String(err), 0);
|
|
110
59
|
setError(apiError);
|
|
111
60
|
throw apiError;
|
|
112
61
|
}
|
|
@@ -120,26 +69,26 @@ function useTemplateRevisions(client, type, locale) {
|
|
|
120
69
|
}
|
|
121
70
|
|
|
122
71
|
// src/hooks/useTemplates.ts
|
|
123
|
-
import { FonderieApiError as
|
|
124
|
-
import { useCallback as
|
|
72
|
+
import { FonderieApiError as FonderieApiError3 } from "@fonderie/client";
|
|
73
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "react";
|
|
125
74
|
function useTemplates(client) {
|
|
126
|
-
const [templates, setTemplates] =
|
|
127
|
-
const [isLoading, setIsLoading] =
|
|
128
|
-
const [error, setError] =
|
|
129
|
-
const refresh =
|
|
75
|
+
const [templates, setTemplates] = useState3([]);
|
|
76
|
+
const [isLoading, setIsLoading] = useState3(true);
|
|
77
|
+
const [error, setError] = useState3(null);
|
|
78
|
+
const refresh = useCallback3(async () => {
|
|
130
79
|
setIsLoading(true);
|
|
131
80
|
setError(null);
|
|
132
81
|
try {
|
|
133
82
|
const { result } = await client.listTemplates();
|
|
134
83
|
setTemplates(result);
|
|
135
84
|
} catch (err) {
|
|
136
|
-
const apiError = err instanceof
|
|
85
|
+
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
137
86
|
setError(apiError);
|
|
138
87
|
} finally {
|
|
139
88
|
setIsLoading(false);
|
|
140
89
|
}
|
|
141
90
|
}, [client]);
|
|
142
|
-
const saveTemplate =
|
|
91
|
+
const saveTemplate = useCallback3(
|
|
143
92
|
async (type, input, locale) => {
|
|
144
93
|
setError(null);
|
|
145
94
|
try {
|
|
@@ -147,21 +96,21 @@ function useTemplates(client) {
|
|
|
147
96
|
await refresh();
|
|
148
97
|
return result;
|
|
149
98
|
} catch (err) {
|
|
150
|
-
const apiError = err instanceof
|
|
99
|
+
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
151
100
|
setError(apiError);
|
|
152
101
|
throw apiError;
|
|
153
102
|
}
|
|
154
103
|
},
|
|
155
104
|
[client, refresh]
|
|
156
105
|
);
|
|
157
|
-
const removeTemplate =
|
|
106
|
+
const removeTemplate = useCallback3(
|
|
158
107
|
async (type, locale) => {
|
|
159
108
|
setError(null);
|
|
160
109
|
try {
|
|
161
110
|
await client.deleteTemplate(type, locale);
|
|
162
111
|
await refresh();
|
|
163
112
|
} catch (err) {
|
|
164
|
-
const apiError = err instanceof
|
|
113
|
+
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
165
114
|
setError(apiError);
|
|
166
115
|
throw apiError;
|
|
167
116
|
}
|
|
@@ -173,12 +122,40 @@ function useTemplates(client) {
|
|
|
173
122
|
}, [refresh]);
|
|
174
123
|
return { templates, isLoading, error, refresh, saveTemplate, removeTemplate };
|
|
175
124
|
}
|
|
125
|
+
|
|
126
|
+
// src/hooks/useTemplatePreview.ts
|
|
127
|
+
import { FonderieApiError as FonderieApiError4 } from "@fonderie/client";
|
|
128
|
+
import { useCallback as useCallback4, useState as useState4 } from "react";
|
|
129
|
+
function useTemplatePreview(client) {
|
|
130
|
+
const [preview, setPreview] = useState4(null);
|
|
131
|
+
const [isPreviewing, setIsPreviewing] = useState4(false);
|
|
132
|
+
const [error, setError] = useState4(null);
|
|
133
|
+
const renderPreview = useCallback4(
|
|
134
|
+
async (type, input, locale) => {
|
|
135
|
+
setIsPreviewing(true);
|
|
136
|
+
setError(null);
|
|
137
|
+
try {
|
|
138
|
+
const { result } = await client.previewTemplate(type, input, locale);
|
|
139
|
+
setPreview(result);
|
|
140
|
+
return result;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
|
|
143
|
+
setError(apiError);
|
|
144
|
+
throw apiError;
|
|
145
|
+
} finally {
|
|
146
|
+
setIsPreviewing(false);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
[client]
|
|
150
|
+
);
|
|
151
|
+
const clearPreview = useCallback4(() => setPreview(null), []);
|
|
152
|
+
return { preview, isPreviewing, error, renderPreview, clearPreview };
|
|
153
|
+
}
|
|
176
154
|
export {
|
|
177
155
|
CourierAdminClient,
|
|
178
|
-
|
|
179
|
-
useDeleteTemplate,
|
|
180
|
-
useSaveTemplate,
|
|
156
|
+
FonderieApiError5 as FonderieApiError,
|
|
181
157
|
useTemplate,
|
|
158
|
+
useTemplatePreview,
|
|
182
159
|
useTemplateRevisions,
|
|
183
160
|
useTemplates
|
|
184
161
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useDeleteTemplate.ts","../src/hooks/useSaveTemplate.ts","../src/hooks/useTemplate.ts","../src/hooks/useTemplateRevisions.ts","../src/hooks/useTemplates.ts"],"sourcesContent":["export type {\n\tICourierAdminClientOptions,\n\tIRollbackTemplateInput,\n\tISetTemplateInput,\n\tITemplateEntry,\n\tITemplateRevision,\n} from '@fonderie/client';\nexport { CourierAdminClient, FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseDeleteTemplateReturn,\n\tIUseSaveTemplateReturn,\n\tIUseTemplateReturn,\n\tIUseTemplateRevisionsReturn,\n\tIUseTemplatesReturn,\n} from './hooks';\nexport {\n\tuseDeleteTemplate,\n\tuseSaveTemplate,\n\tuseTemplate,\n\tuseTemplateRevisions,\n\tuseTemplates,\n} from './hooks';\n","import type { CourierAdminClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseDeleteTemplateReturn {\n\tdeleteTemplate: (type: string, locale?: string | null) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n/** @deprecated Use `useTemplates().removeTemplate` instead — it refreshes the list after deleting. */\nexport function useDeleteTemplate(client: CourierAdminClient): IUseDeleteTemplateReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst deleteTemplate = useCallback(\n\t\tasync (type: string, locale?: string | null) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deleteTemplate(type, locale);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { deleteTemplate, isLoading, error };\n}\n","import type { CourierAdminClient, ISetTemplateInput, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseSaveTemplateReturn {\n\tsaveTemplate: (\n\t\ttype: string,\n\t\tinput: ISetTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<ITemplateEntry>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n/** @deprecated Use `useTemplates().saveTemplate` instead — it refreshes the list after saving. */\nexport function useSaveTemplate(client: CourierAdminClient): IUseSaveTemplateReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst saveTemplate = useCallback(\n\t\tasync (type: string, input: ISetTemplateInput, locale?: string | null) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.setTemplate(type, input, locale);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { saveTemplate, isLoading, error };\n}\n","import type { CourierAdminClient, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateReturn {\n\ttemplate: ITemplateEntry | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function useTemplate(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateReturn {\n\tconst [template, setTemplate] = useState<ITemplateEntry | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getTemplate(type, locale);\n\t\t\tsetTemplate(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { template, isLoading, error, refresh };\n}\n","import type { CourierAdminClient, ITemplateEntry, ITemplateRevision } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateRevisionsReturn {\n\trevisions: ITemplateRevision[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\trollback: (toVersion: number) => Promise<ITemplateEntry>;\n}\n\nexport function useTemplateRevisions(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateRevisionsReturn {\n\tconst [revisions, setRevisions] = useState<ITemplateRevision[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listRevisions(type, locale);\n\t\t\tsetRevisions(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tconst rollback = useCallback(\n\t\tasync (toVersion: number) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.rollback(type, { toVersion }, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, type, locale, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { revisions, isLoading, error, refresh, rollback };\n}\n","import type { CourierAdminClient, ISetTemplateInput, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplatesReturn {\n\ttemplates: ITemplateEntry[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\tsaveTemplate: (\n\t\ttype: string,\n\t\tinput: ISetTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<ITemplateEntry>;\n\tremoveTemplate: (type: string, locale?: string | null) => Promise<void>;\n}\n\nexport function useTemplates(client: CourierAdminClient): IUseTemplatesReturn {\n\tconst [templates, setTemplates] = useState<ITemplateEntry[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listTemplates();\n\t\t\tsetTemplates(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tconst saveTemplate = useCallback(\n\t\tasync (type: string, input: ISetTemplateInput, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.setTemplate(type, input, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tconst removeTemplate = useCallback(\n\t\tasync (type: string, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deleteTemplate(type, locale);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { templates, isLoading, error, refresh, saveTemplate, removeTemplate };\n}\n"],"mappings":";AAOA,SAAS,oBAAoB,oBAAAA,yBAAwB;;;ACNrD,SAAS,wBAAwB;AACjC,SAAS,aAAa,gBAAgB;AAS/B,SAAS,kBAAkB,QAAsD;AACvF,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC,IAAI;AAEhE,QAAM,iBAAiB;AAAA,IACtB,OAAO,MAAc,WAA2B;AAC/C,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,OAAO,eAAe,MAAM,MAAM;AAAA,MACzC,SAAS,KAAK;AACb,cAAM,WACL,eAAe,mBAAmB,MAAM,IAAI,iBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAEA,SAAO,EAAE,gBAAgB,WAAW,MAAM;AAC3C;;;ACjCA,SAAS,oBAAAC,yBAAwB;AACjC,SAAS,eAAAC,cAAa,YAAAC,iBAAgB;AAa/B,SAAS,gBAAgB,QAAoD;AACnF,QAAM,CAAC,WAAW,YAAY,IAAIA,UAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAkC,IAAI;AAEhE,QAAM,eAAeD;AAAA,IACpB,OAAO,MAAc,OAA0B,WAA2B;AACzE,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,OAAO,YAAY,MAAM,OAAO,MAAM;AAC/D,eAAO;AAAA,MACR,SAAS,KAAK;AACb,cAAM,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;AAC7E;","names":["FonderieApiError","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useEffect","useState","FonderieApiError","useCallback","useEffect","useState"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/useTemplate.ts","../src/hooks/useTemplateRevisions.ts","../src/hooks/useTemplates.ts","../src/hooks/useTemplatePreview.ts"],"sourcesContent":["export type {\n\tICourierAdminClientOptions,\n\tIPreviewTemplateInput,\n\tIRenderedTemplateResult,\n\tIRollbackTemplateInput,\n\tISetTemplateInput,\n\tITemplateEntry,\n\tITemplateRevision,\n} from '@fonderie/client';\nexport { CourierAdminClient, FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseTemplatePreviewReturn,\n\tIUseTemplateReturn,\n\tIUseTemplateRevisionsReturn,\n\tIUseTemplatesReturn,\n} from './hooks';\nexport {\n\tuseTemplate,\n\tuseTemplatePreview,\n\tuseTemplateRevisions,\n\tuseTemplates,\n} from './hooks';\n","import type { CourierAdminClient, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateReturn {\n\ttemplate: ITemplateEntry | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function useTemplate(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateReturn {\n\tconst [template, setTemplate] = useState<ITemplateEntry | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getTemplate(type, locale);\n\t\t\tsetTemplate(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { template, isLoading, error, refresh };\n}\n","import type { CourierAdminClient, ITemplateEntry, ITemplateRevision } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplateRevisionsReturn {\n\trevisions: ITemplateRevision[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\trollback: (toVersion: number) => Promise<ITemplateEntry>;\n}\n\nexport function useTemplateRevisions(\n\tclient: CourierAdminClient,\n\ttype: string,\n\tlocale?: string | null,\n): IUseTemplateRevisionsReturn {\n\tconst [revisions, setRevisions] = useState<ITemplateRevision[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listRevisions(type, locale);\n\t\t\tsetRevisions(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, type, locale]);\n\n\tconst rollback = useCallback(\n\t\tasync (toVersion: number) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.rollback(type, { toVersion }, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, type, locale, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { revisions, isLoading, error, refresh, rollback };\n}\n","import type { CourierAdminClient, ISetTemplateInput, ITemplateEntry } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseTemplatesReturn {\n\ttemplates: ITemplateEntry[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n\tsaveTemplate: (\n\t\ttype: string,\n\t\tinput: ISetTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<ITemplateEntry>;\n\tremoveTemplate: (type: string, locale?: string | null) => Promise<void>;\n}\n\nexport function useTemplates(client: CourierAdminClient): IUseTemplatesReturn {\n\tconst [templates, setTemplates] = useState<ITemplateEntry[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listTemplates();\n\t\t\tsetTemplates(result);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tconst saveTemplate = useCallback(\n\t\tasync (type: string, input: ISetTemplateInput, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.setTemplate(type, input, locale);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tconst removeTemplate = useCallback(\n\t\tasync (type: string, locale?: string | null) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deleteTemplate(type, locale);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[client, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { templates, isLoading, error, refresh, saveTemplate, removeTemplate };\n}\n","import type {\n\tCourierAdminClient,\n\tIPreviewTemplateInput,\n\tIRenderedTemplateResult,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseTemplatePreviewReturn {\n\tpreview: IRenderedTemplateResult | null;\n\tisPreviewing: boolean;\n\terror: FonderieApiError | null;\n\trenderPreview: (\n\t\ttype: string,\n\t\tinput: IPreviewTemplateInput,\n\t\tlocale?: string | null,\n\t) => Promise<IRenderedTemplateResult>;\n\tclearPreview: () => void;\n}\n\n// On demand, not on mount: the caller decides when the editor's content is\n// worth rendering. Server-side, so what comes back is what the resolver\n// produces — the layout shell and the variable substitution included.\nexport function useTemplatePreview(client: CourierAdminClient): IUseTemplatePreviewReturn {\n\tconst [preview, setPreview] = useState<IRenderedTemplateResult | null>(null);\n\tconst [isPreviewing, setIsPreviewing] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst renderPreview = useCallback(\n\t\tasync (type: string, input: IPreviewTemplateInput, locale?: string | null) => {\n\t\t\tsetIsPreviewing(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.previewTemplate(type, input, locale);\n\t\t\t\tsetPreview(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsPreviewing(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\tconst clearPreview = useCallback(() => setPreview(null), []);\n\n\treturn { preview, isPreviewing, error, renderPreview, clearPreview };\n}\n"],"mappings":";AASA,SAAS,oBAAoB,oBAAAA,yBAAwB;;;ACRrD,SAAS,wBAAwB;AACjC,SAAS,aAAa,WAAW,gBAAgB;AAS1C,SAAS,YACf,QACA,MACA,QACqB;AACrB,QAAM,CAAC,UAAU,WAAW,IAAI,SAAgC,IAAI;AACpE,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC,IAAI;AAEhE,QAAM,UAAU,YAAY,YAAY;AACvC,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,YAAY,MAAM,MAAM;AACxD,kBAAY,MAAM;AAAA,IACnB,SAAS,KAAK;AACb,YAAM,WACL,eAAe,mBAAmB,MAAM,IAAI,iBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,eAAS,QAAQ;AAAA,IAClB,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,QAAQ,MAAM,MAAM,CAAC;AAEzB,YAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,UAAU,WAAW,OAAO,QAAQ;AAC9C;;;ACvCA,SAAS,oBAAAC,yBAAwB;AACjC,SAAS,eAAAC,cAAa,aAAAC,YAAW,YAAAC,iBAAgB;AAU1C,SAAS,qBACf,QACA,MACA,QAC8B;AAC9B,QAAM,CAAC,WAAW,YAAY,IAAIA,UAA8B,CAAC,CAAC;AAClE,QAAM,CAAC,WAAW,YAAY,IAAIA,UAAS,IAAI;AAC/C,QAA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SAAS,oBAAAE,yBAAwB;AACjC,SAAS,eAAAC,cAAa,YAAAC,iBAAgB;AAiB/B,SAAS,mBAAmB,QAAuD;AACzF,QAAM,CAAC,SAAS,UAAU,IAAIA,UAAyC,IAAI;AAC3E,QAAM,CAAC,cAAc,eAAe,IAAIA,UAAS,KAAK;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAkC,IAAI;AAEhE,QAAM,gBAAgBD;AAAA,IACrB,OAAO,MAAc,OAA8B,WAA2B;AAC7E,sBAAgB,IAAI;AACpB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,OAAO,gBAAgB,MAAM,OAAO,MAAM;AACnE,mBAAW,MAAM;AACjB,eAAO;AAAA,MACR,SAAS,KAAK;AACb,cAAM,WACL,eAAeD,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,wBAAgB,KAAK;AAAA,MACtB;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAEA,QAAM,eAAeC,aAAY,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAE3D,SAAO,EAAE,SAAS,cAAc,OAAO,eAAe,aAAa;AACpE;","names":["FonderieApiError","FonderieApiError","useCallback","useEffect","useState","FonderieApiError","useCallback","useEffect","useState","FonderieApiError","useCallback","useState"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonderie/react-courier-admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "React hooks for the Fonderie courier admin API (email/SMS/push template management) — thin bindings over @fonderie/client's CourierAdminClient.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fonderiejs",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"react": ">=18.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/node": "^26.
|
|
45
|
-
"@types/react": "^19.
|
|
46
|
-
"react": "^19.
|
|
44
|
+
"@types/node": "^26.6.1",
|
|
45
|
+
"@types/react": "^19.3.0",
|
|
46
|
+
"react": "^19.3.0",
|
|
47
47
|
"tsup": "^8.5.1",
|
|
48
48
|
"typescript": "^6.0.3"
|
|
49
49
|
},
|