@fonderie/react-courier-admin 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fonderie, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @fonderie/react-courier-admin
2
+
3
+ React hooks for the Fonderie courier admin API — `useTemplates`,
4
+ `useTemplate`, `useSaveTemplate`, `useDeleteTemplate`, and
5
+ `useTemplateRevisions` (list + rollback). Thin bindings over
6
+ [`@fonderie/client`](https://github.com/fonderie-js/sdk/tree/main/packages/client)'s
7
+ `CourierAdminClient`: loading/error state and the request itself, nothing
8
+ else. Bring your own UI.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm install @fonderie/react-courier-admin
14
+ ```
15
+
16
+ ## Use
17
+
18
+ ```tsx
19
+ import { CourierAdminClient } from '@fonderie/client';
20
+ import { useTemplates, useSaveTemplate } from '@fonderie/react-courier-admin';
21
+
22
+ const admin = new CourierAdminClient({
23
+ baseUrl: 'https://api.example.com/v1',
24
+ adminToken: process.env.FONDERIE_ADMIN_TOKEN!,
25
+ });
26
+
27
+ function TemplateList() {
28
+ const { templates, isLoading } = useTemplates(admin);
29
+ return <ul>{templates.map((t) => <li key={t.type}>{t.type}</li>)}</ul>;
30
+ }
31
+
32
+ function EditTemplate({ type }: { type: string }) {
33
+ const { saveTemplate, isLoading } = useSaveTemplate(admin);
34
+ return (
35
+ <button onClick={() => saveTemplate(type, { text: 'Hi {{name}}' })} disabled={isLoading}>
36
+ Save
37
+ </button>
38
+ );
39
+ }
40
+ ```
41
+
42
+ **This client is deliberately separate from `FonderieClient`.** Courier's
43
+ `/admin/templates/*` routes are guarded by a static bearer token configured
44
+ on the server (`CourierModule`'s `adminToken`), not the signed-in user's
45
+ session — the same model `@fonderie/config`'s admin surface and the
46
+ `fonderie template`/`fonderie config` CLI commands use. Construct
47
+ `CourierAdminClient` with that token directly; it does not share state with
48
+ `AuthClient`/`BillingClient`/`WorkspacesClient`.
49
+
50
+ Want pre-built screens instead of wiring your own editor?
51
+ See [`@fonderie/react-courier-admin-screens`](https://github.com/fonderie-js/sdk/tree/main/packages/react-courier-admin-screens).
52
+
53
+ ## Why this exists
54
+
55
+ You've shipped this plumbing before — auth, teams, billing, messaging —
56
+ and the next project will ask for it again. Fonderie packages it once:
57
+ plain TypeScript modules for
58
+ [`@fonderie/core`](https://github.com/fonderie-js/sdk/tree/main/packages/core),
59
+ PostgreSQL-backed, self-hosted, MIT. No external control plane, no
60
+ per-seat anything. Register the modules you need; skip the ones you don't.
61
+
62
+ **This package owns** the React binding for courier's template admin API —
63
+ state management around `@fonderie/client`, nothing more. No business logic
64
+ lives here; it lives in `@fonderie/courier` on the server.
65
+
66
+ Browse the whole set at
67
+ [fonderie-js/sdk](https://github.com/fonderie-js/sdk) · follow
68
+ [@fonderiejs](https://x.com/fonderiejs)
69
+
70
+ ## License
71
+
72
+ MIT © Fonderie, Inc.
package/dist/index.cjs ADDED
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CourierAdminClient: () => import_client6.CourierAdminClient,
24
+ FonderieApiError: () => import_client6.FonderieApiError,
25
+ useDeleteTemplate: () => useDeleteTemplate,
26
+ useSaveTemplate: () => useSaveTemplate,
27
+ useTemplate: () => useTemplate,
28
+ useTemplateRevisions: () => useTemplateRevisions,
29
+ useTemplates: () => useTemplates
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var import_client6 = require("@fonderie/client");
33
+
34
+ // src/hooks/useDeleteTemplate.ts
35
+ var import_client = require("@fonderie/client");
36
+ 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
+ function useTemplate(client, type, locale) {
89
+ const [template, setTemplate] = (0, import_react3.useState)(null);
90
+ const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
91
+ const [error, setError] = (0, import_react3.useState)(null);
92
+ const refresh = (0, import_react3.useCallback)(async () => {
93
+ setIsLoading(true);
94
+ setError(null);
95
+ try {
96
+ const { result } = await client.getTemplate(type, locale);
97
+ setTemplate(result);
98
+ } catch (err) {
99
+ const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
100
+ setError(apiError);
101
+ } finally {
102
+ setIsLoading(false);
103
+ }
104
+ }, [client, type, locale]);
105
+ (0, import_react3.useEffect)(() => {
106
+ void refresh();
107
+ }, [refresh]);
108
+ return { template, isLoading, error, refresh };
109
+ }
110
+
111
+ // src/hooks/useTemplateRevisions.ts
112
+ var import_client4 = require("@fonderie/client");
113
+ var import_react4 = require("react");
114
+ function useTemplateRevisions(client, type, locale) {
115
+ const [revisions, setRevisions] = (0, import_react4.useState)([]);
116
+ const [isLoading, setIsLoading] = (0, import_react4.useState)(true);
117
+ const [error, setError] = (0, import_react4.useState)(null);
118
+ const refresh = (0, import_react4.useCallback)(async () => {
119
+ setIsLoading(true);
120
+ setError(null);
121
+ try {
122
+ const { result } = await client.listRevisions(type, locale);
123
+ setRevisions(result);
124
+ } catch (err) {
125
+ const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
126
+ setError(apiError);
127
+ } finally {
128
+ setIsLoading(false);
129
+ }
130
+ }, [client, type, locale]);
131
+ const rollback = (0, import_react4.useCallback)(
132
+ async (toVersion) => {
133
+ setError(null);
134
+ try {
135
+ const { result } = await client.rollback(type, { toVersion }, locale);
136
+ await refresh();
137
+ return result;
138
+ } catch (err) {
139
+ const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
140
+ setError(apiError);
141
+ throw apiError;
142
+ }
143
+ },
144
+ [client, type, locale, refresh]
145
+ );
146
+ (0, import_react4.useEffect)(() => {
147
+ void refresh();
148
+ }, [refresh]);
149
+ return { revisions, isLoading, error, refresh, rollback };
150
+ }
151
+
152
+ // src/hooks/useTemplates.ts
153
+ var import_client5 = require("@fonderie/client");
154
+ var import_react5 = require("react");
155
+ function useTemplates(client) {
156
+ const [templates, setTemplates] = (0, import_react5.useState)([]);
157
+ const [isLoading, setIsLoading] = (0, import_react5.useState)(true);
158
+ const [error, setError] = (0, import_react5.useState)(null);
159
+ const refresh = (0, import_react5.useCallback)(async () => {
160
+ setIsLoading(true);
161
+ setError(null);
162
+ try {
163
+ const { result } = await client.listTemplates();
164
+ setTemplates(result);
165
+ } catch (err) {
166
+ const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
167
+ setError(apiError);
168
+ } finally {
169
+ setIsLoading(false);
170
+ }
171
+ }, [client]);
172
+ (0, import_react5.useEffect)(() => {
173
+ void refresh();
174
+ }, [refresh]);
175
+ return { templates, isLoading, error, refresh };
176
+ }
177
+ // Annotate the CommonJS export names for ESM import in node:
178
+ 0 && (module.exports = {
179
+ CourierAdminClient,
180
+ FonderieApiError,
181
+ useDeleteTemplate,
182
+ useSaveTemplate,
183
+ useTemplate,
184
+ useTemplateRevisions,
185
+ useTemplates
186
+ });
187
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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\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\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, 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}\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]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AK;AACb,YAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,eAAS,QAAQ;AAAA,IAClB,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAEX,+BAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,WAAW,WAAW,OAAO,QAAQ;AAC/C;","names":["import_client","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react"]}
@@ -0,0 +1,43 @@
1
+ import { FonderieApiError, CourierAdminClient, ISetTemplateInput, ITemplateEntry, ITemplateRevision } from '@fonderie/client';
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
+ declare function useDeleteTemplate(client: CourierAdminClient): IUseDeleteTemplateReturn;
10
+
11
+ interface IUseSaveTemplateReturn {
12
+ saveTemplate: (type: string, input: ISetTemplateInput, locale?: string | null) => Promise<ITemplateEntry>;
13
+ isLoading: boolean;
14
+ error: FonderieApiError | null;
15
+ }
16
+ declare function useSaveTemplate(client: CourierAdminClient): IUseSaveTemplateReturn;
17
+
18
+ interface IUseTemplateReturn {
19
+ template: ITemplateEntry | null;
20
+ isLoading: boolean;
21
+ error: FonderieApiError | null;
22
+ refresh: () => Promise<void>;
23
+ }
24
+ declare function useTemplate(client: CourierAdminClient, type: string, locale?: string | null): IUseTemplateReturn;
25
+
26
+ interface IUseTemplateRevisionsReturn {
27
+ revisions: ITemplateRevision[];
28
+ isLoading: boolean;
29
+ error: FonderieApiError | null;
30
+ refresh: () => Promise<void>;
31
+ rollback: (toVersion: number) => Promise<ITemplateEntry>;
32
+ }
33
+ declare function useTemplateRevisions(client: CourierAdminClient, type: string, locale?: string | null): IUseTemplateRevisionsReturn;
34
+
35
+ interface IUseTemplatesReturn {
36
+ templates: ITemplateEntry[];
37
+ isLoading: boolean;
38
+ error: FonderieApiError | null;
39
+ refresh: () => Promise<void>;
40
+ }
41
+ declare function useTemplates(client: CourierAdminClient): IUseTemplatesReturn;
42
+
43
+ export { type IUseDeleteTemplateReturn, type IUseSaveTemplateReturn, type IUseTemplateReturn, type IUseTemplateRevisionsReturn, type IUseTemplatesReturn, useDeleteTemplate, useSaveTemplate, useTemplate, useTemplateRevisions, useTemplates };
@@ -0,0 +1,43 @@
1
+ import { FonderieApiError, CourierAdminClient, ISetTemplateInput, ITemplateEntry, ITemplateRevision } from '@fonderie/client';
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
+ declare function useDeleteTemplate(client: CourierAdminClient): IUseDeleteTemplateReturn;
10
+
11
+ interface IUseSaveTemplateReturn {
12
+ saveTemplate: (type: string, input: ISetTemplateInput, locale?: string | null) => Promise<ITemplateEntry>;
13
+ isLoading: boolean;
14
+ error: FonderieApiError | null;
15
+ }
16
+ declare function useSaveTemplate(client: CourierAdminClient): IUseSaveTemplateReturn;
17
+
18
+ interface IUseTemplateReturn {
19
+ template: ITemplateEntry | null;
20
+ isLoading: boolean;
21
+ error: FonderieApiError | null;
22
+ refresh: () => Promise<void>;
23
+ }
24
+ declare function useTemplate(client: CourierAdminClient, type: string, locale?: string | null): IUseTemplateReturn;
25
+
26
+ interface IUseTemplateRevisionsReturn {
27
+ revisions: ITemplateRevision[];
28
+ isLoading: boolean;
29
+ error: FonderieApiError | null;
30
+ refresh: () => Promise<void>;
31
+ rollback: (toVersion: number) => Promise<ITemplateEntry>;
32
+ }
33
+ declare function useTemplateRevisions(client: CourierAdminClient, type: string, locale?: string | null): IUseTemplateRevisionsReturn;
34
+
35
+ interface IUseTemplatesReturn {
36
+ templates: ITemplateEntry[];
37
+ isLoading: boolean;
38
+ error: FonderieApiError | null;
39
+ refresh: () => Promise<void>;
40
+ }
41
+ declare function useTemplates(client: CourierAdminClient): IUseTemplatesReturn;
42
+
43
+ export { type IUseDeleteTemplateReturn, type IUseSaveTemplateReturn, type IUseTemplateReturn, type IUseTemplateRevisionsReturn, type IUseTemplatesReturn, useDeleteTemplate, useSaveTemplate, useTemplate, useTemplateRevisions, useTemplates };
package/dist/index.js ADDED
@@ -0,0 +1,156 @@
1
+ // src/index.ts
2
+ import { CourierAdminClient, FonderieApiError as FonderieApiError6 } from "@fonderie/client";
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
+ }
54
+
55
+ // src/hooks/useTemplate.ts
56
+ import { FonderieApiError as FonderieApiError3 } from "@fonderie/client";
57
+ import { useCallback as useCallback3, useEffect, useState as useState3 } from "react";
58
+ function useTemplate(client, type, locale) {
59
+ const [template, setTemplate] = useState3(null);
60
+ const [isLoading, setIsLoading] = useState3(true);
61
+ const [error, setError] = useState3(null);
62
+ const refresh = useCallback3(async () => {
63
+ setIsLoading(true);
64
+ setError(null);
65
+ try {
66
+ const { result } = await client.getTemplate(type, locale);
67
+ setTemplate(result);
68
+ } catch (err) {
69
+ const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
70
+ setError(apiError);
71
+ } finally {
72
+ setIsLoading(false);
73
+ }
74
+ }, [client, type, locale]);
75
+ useEffect(() => {
76
+ void refresh();
77
+ }, [refresh]);
78
+ return { template, isLoading, error, refresh };
79
+ }
80
+
81
+ // src/hooks/useTemplateRevisions.ts
82
+ import { FonderieApiError as FonderieApiError4 } from "@fonderie/client";
83
+ import { useCallback as useCallback4, useEffect as useEffect2, useState as useState4 } from "react";
84
+ function useTemplateRevisions(client, type, locale) {
85
+ const [revisions, setRevisions] = useState4([]);
86
+ const [isLoading, setIsLoading] = useState4(true);
87
+ const [error, setError] = useState4(null);
88
+ const refresh = useCallback4(async () => {
89
+ setIsLoading(true);
90
+ setError(null);
91
+ try {
92
+ const { result } = await client.listRevisions(type, locale);
93
+ setRevisions(result);
94
+ } catch (err) {
95
+ const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
96
+ setError(apiError);
97
+ } finally {
98
+ setIsLoading(false);
99
+ }
100
+ }, [client, type, locale]);
101
+ const rollback = useCallback4(
102
+ async (toVersion) => {
103
+ setError(null);
104
+ try {
105
+ const { result } = await client.rollback(type, { toVersion }, locale);
106
+ await refresh();
107
+ return result;
108
+ } catch (err) {
109
+ const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
110
+ setError(apiError);
111
+ throw apiError;
112
+ }
113
+ },
114
+ [client, type, locale, refresh]
115
+ );
116
+ useEffect2(() => {
117
+ void refresh();
118
+ }, [refresh]);
119
+ return { revisions, isLoading, error, refresh, rollback };
120
+ }
121
+
122
+ // src/hooks/useTemplates.ts
123
+ import { FonderieApiError as FonderieApiError5 } from "@fonderie/client";
124
+ import { useCallback as useCallback5, useEffect as useEffect3, useState as useState5 } from "react";
125
+ function useTemplates(client) {
126
+ const [templates, setTemplates] = useState5([]);
127
+ const [isLoading, setIsLoading] = useState5(true);
128
+ const [error, setError] = useState5(null);
129
+ const refresh = useCallback5(async () => {
130
+ setIsLoading(true);
131
+ setError(null);
132
+ try {
133
+ const { result } = await client.listTemplates();
134
+ setTemplates(result);
135
+ } catch (err) {
136
+ const apiError = err instanceof FonderieApiError5 ? err : new FonderieApiError5("unknown", String(err), 0);
137
+ setError(apiError);
138
+ } finally {
139
+ setIsLoading(false);
140
+ }
141
+ }, [client]);
142
+ useEffect3(() => {
143
+ void refresh();
144
+ }, [refresh]);
145
+ return { templates, isLoading, error, refresh };
146
+ }
147
+ export {
148
+ CourierAdminClient,
149
+ FonderieApiError6 as FonderieApiError,
150
+ useDeleteTemplate,
151
+ useSaveTemplate,
152
+ useTemplate,
153
+ useTemplateRevisions,
154
+ useTemplates
155
+ };
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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\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\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, 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}\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\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { templates, isLoading, error, refresh };\n}\n"],"mappings":";AAOA,SAAS,oBAAoB,oBAAAA,yBAAwB;;;ACNrD,SAAS,wBAAwB;AACjC,SAAS,aAAa,gBAAgB;AAQ/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,OA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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;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,MAAM,QAAQ,OAAO;AAAA,EAC/B;AAEA,EAAAE,WAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,WAAW,WAAW,OAAO,SAAS,SAAS;AACzD;;;ACzDA,SAAS,oBAAAE,yBAAwB;AACjC,SAAS,eAAAC,cAAa,aAAAC,YAAW,YAAAC,iBAAgB;AAS1C,SAAS,aAAa,QAAiD;AAC7E,QAAM,CAAC,WAAW,YAAY,IAAIA,UAA2B,CAAC,CAAC;AAC/D,QAAM,CAAC,WAAW,YAAY,IAAIA,UAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAkC,IAAI;AAEhE,QAAM,UAAUF,aAAY,YAAY;AACvC,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,cAAc;AAC9C,mBAAa,MAAM;AAAA,IACpB,SAAS,KAAK;AACb,YAAM,WACL,eAAeD,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,eAAS,QAAQ;AAAA,IAClB,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAEX,EAAAE,WAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,WAAW,WAAW,OAAO,QAAQ;AAC/C;","names":["FonderieApiError","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useEffect","useState","FonderieApiError","useCallback","useEffect","useState"]}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@fonderie/react-courier-admin",
3
+ "version": "0.1.0",
4
+ "description": "React hooks for the Fonderie courier admin API (email/SMS/push template management) — thin bindings over @fonderie/client's CourierAdminClient.",
5
+ "keywords": [
6
+ "fonderie-js",
7
+ "react",
8
+ "courier",
9
+ "templates",
10
+ "admin",
11
+ "hooks",
12
+ "typescript"
13
+ ],
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=20"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
32
+ "typecheck": "tsc --noEmit",
33
+ "lint": "biome lint src",
34
+ "format": "biome format --write src",
35
+ "check": "biome check --write src"
36
+ },
37
+ "dependencies": {
38
+ "@fonderie/client": "*"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=18.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^25.6.0",
45
+ "@types/react": "^18.0.0",
46
+ "react": "^18.0.0",
47
+ "tsup": "^8.5.1",
48
+ "typescript": "^6.0.3"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "LICENSE",
56
+ "README.md"
57
+ ],
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/fonderiejs/fonderie.git",
61
+ "directory": "packages/react-courier-admin"
62
+ },
63
+ "homepage": "https://github.com/fonderiejs/fonderie/tree/main/packages/react-courier-admin#readme",
64
+ "bugs": {
65
+ "url": "https://github.com/fonderiejs/fonderie/issues"
66
+ }
67
+ }