@dev-crew-berlin/enter-js-utils 0.99.0 → 0.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -935,4 +935,113 @@ describe('createEvents', () => {
935
935
  expect(result.data.created).toBe(0);
936
936
  expect(result.data.eventCursors).toEqual({});
937
937
  });
938
+ });
939
+ describe('getEmailContent', () => {
940
+ afterEach(() => {
941
+ vi.restoreAllMocks();
942
+ });
943
+ it('returns the parsed content on success', async () => {
944
+ const content = {
945
+ subject: {
946
+ type: 'text',
947
+ content: 'Hello'
948
+ },
949
+ to: {
950
+ type: 'text',
951
+ content: 'a@b.com'
952
+ },
953
+ to_name: {
954
+ type: 'text',
955
+ content: ''
956
+ },
957
+ from: {
958
+ type: 'text',
959
+ content: 'sender@example.com'
960
+ },
961
+ cc: {
962
+ type: 'text',
963
+ content: ''
964
+ },
965
+ bcc: {
966
+ type: 'text',
967
+ content: ''
968
+ },
969
+ reply: {
970
+ type: 'text',
971
+ content: ''
972
+ },
973
+ pre: {
974
+ type: 'text',
975
+ content: ''
976
+ },
977
+ pdf: {
978
+ type: 'text',
979
+ content: ''
980
+ },
981
+ pdfname: {
982
+ type: 'text',
983
+ content: ''
984
+ },
985
+ blocks: []
986
+ };
987
+ vi.stubGlobal('fetch', () => Promise.resolve(new Response(JSON.stringify(content), {
988
+ status: 200
989
+ })));
990
+ const api = makeFullAPI();
991
+ const result = await api.getEmailContent({
992
+ instanceName: 'test-instance',
993
+ emailName: 'welcome'
994
+ });
995
+ expect(result.success).toBe(true);
996
+ if (!result.success) return;
997
+ expect(result.data).toEqual(content);
998
+ });
999
+ it('maps a 404 to a failure result', async () => {
1000
+ vi.stubGlobal('fetch', () => Promise.resolve(new Response(null, {
1001
+ status: 404
1002
+ })));
1003
+ const api = makeFullAPI();
1004
+ const result = await api.getEmailContent({
1005
+ instanceName: 'test-instance',
1006
+ emailName: 'missing'
1007
+ });
1008
+ expect(result.success).toBe(false);
1009
+ if (result.success) return;
1010
+ expect(result.error[0]).toMatchObject({
1011
+ statusCode: 404
1012
+ });
1013
+ });
1014
+ });
1015
+ describe('getLegacyTemplateSource', () => {
1016
+ afterEach(() => {
1017
+ vi.restoreAllMocks();
1018
+ });
1019
+ it('returns the parsed template source string on success', async () => {
1020
+ vi.stubGlobal('fetch', () => Promise.resolve(new Response(JSON.stringify('<p>{{userdata.vorname}}</p>'), {
1021
+ status: 200
1022
+ })));
1023
+ const api = makeFullAPI();
1024
+ const result = await api.getLegacyTemplateSource({
1025
+ instanceName: 'test-instance',
1026
+ templateName: 'footer'
1027
+ });
1028
+ expect(result.success).toBe(true);
1029
+ if (!result.success) return;
1030
+ expect(result.data).toBe('<p>{{userdata.vorname}}</p>');
1031
+ });
1032
+ it('maps a 404 to a failure result', async () => {
1033
+ vi.stubGlobal('fetch', () => Promise.resolve(new Response(null, {
1034
+ status: 404
1035
+ })));
1036
+ const api = makeFullAPI();
1037
+ const result = await api.getLegacyTemplateSource({
1038
+ instanceName: 'test-instance',
1039
+ templateName: 'missing'
1040
+ });
1041
+ expect(result.success).toBe(false);
1042
+ if (result.success) return;
1043
+ expect(result.error[0]).toMatchObject({
1044
+ statusCode: 404
1045
+ });
1046
+ });
938
1047
  });
@@ -9,6 +9,7 @@ import { User } from '../models/user';
9
9
  import { Variable } from '../models/variable';
10
10
  import { components } from '../generated/api-schema';
11
11
  import { Email } from '../models/email';
12
+ import { PublicEmailContent } from '../models/email-content';
12
13
  export type { APICredentials, SubscribeOptions } from './api-base';
13
14
  /**
14
15
  * api client for the enter backend
@@ -160,6 +161,26 @@ declare class API extends APIBase {
160
161
  emailName: string;
161
162
  mailingId?: string | null;
162
163
  }, options?: FetchOptions): Promise<APIResult<Email>>;
164
+ /**
165
+ * @category Emails
166
+ *
167
+ * TODO: switch to the typed `get()` helper once enter-core MR !2007 lands
168
+ * and `npm run generate-client` adds this path to `paths`.
169
+ */
170
+ getEmailContent(args: {
171
+ instanceName: string;
172
+ emailName: string;
173
+ }, options?: FetchOptions): Promise<APIResult<PublicEmailContent>>;
174
+ /**
175
+ * @category Templates
176
+ *
177
+ * TODO: switch to the typed `get()` helper once enter-core MR !2007 lands
178
+ * and `npm run generate-client` adds this path to `paths`.
179
+ */
180
+ getLegacyTemplateSource(args: {
181
+ instanceName: string;
182
+ templateName: string;
183
+ }, options?: FetchOptions): Promise<APIResult<string>>;
163
184
  /**
164
185
  * @category Events
165
186
  */
@@ -224,6 +224,38 @@ class API extends APIBase {
224
224
  return this.get(`/instances/${instanceName}/attendees/${attendeeId}/emails/${emailName}/render${queryString}`, options);
225
225
  }
226
226
 
227
+ /**
228
+ * @category Emails
229
+ *
230
+ * TODO: switch to the typed `get()` helper once enter-core MR !2007 lands
231
+ * and `npm run generate-client` adds this path to `paths`.
232
+ */
233
+ async getEmailContent(args, options = {}) {
234
+ const result = await this.fetchResponse(`/instances/${args.instanceName}/emails/${args.emailName}/content`, {
235
+ method: 'GET',
236
+ headers: this.buildHeaders(),
237
+ ...options
238
+ });
239
+ if (!result.success) return result;
240
+ return success(await result.data.json());
241
+ }
242
+
243
+ /**
244
+ * @category Templates
245
+ *
246
+ * TODO: switch to the typed `get()` helper once enter-core MR !2007 lands
247
+ * and `npm run generate-client` adds this path to `paths`.
248
+ */
249
+ async getLegacyTemplateSource(args, options = {}) {
250
+ const result = await this.fetchResponse(`/instances/${args.instanceName}/templates/${args.templateName}`, {
251
+ method: 'GET',
252
+ headers: this.buildHeaders(),
253
+ ...options
254
+ });
255
+ if (!result.success) return result;
256
+ return success(await result.data.json());
257
+ }
258
+
227
259
  /**
228
260
  * @category Events
229
261
  */
@@ -0,0 +1,23 @@
1
+ export type ContentValue = {
2
+ type: 'handlebars' | 'text';
3
+ content: string;
4
+ };
5
+ export type EmailContentBlock = {
6
+ key: string;
7
+ name: string;
8
+ sort_order: number;
9
+ value: ContentValue;
10
+ };
11
+ export type PublicEmailContent = {
12
+ subject: ContentValue;
13
+ to: ContentValue;
14
+ to_name: ContentValue;
15
+ from: ContentValue;
16
+ cc: ContentValue;
17
+ bcc: ContentValue;
18
+ reply: ContentValue;
19
+ pre: ContentValue;
20
+ pdf: ContentValue;
21
+ pdfname: ContentValue;
22
+ blocks: EmailContentBlock[];
23
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -16,6 +16,7 @@ export type { FieldValue } from './field-value';
16
16
  export type { TextField, EmailField, NumberField, CheckboxField, ToggleField, RadioField, SelectField, Field, } from './field';
17
17
  export { Instance } from './instance';
18
18
  export type { InstanceJSON } from './instance';
19
+ export type { ContentValue, EmailContentBlock, PublicEmailContent, } from './email-content';
19
20
  export type { Permission } from './permission';
20
21
  export type { User } from './user';
21
22
  export type { Variable } from './variable';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.99.0",
3
+ "version": "0.99.1",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",