@ampsec/platform-client 55.7.0 → 55.7.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.
@@ -1,5 +1,4 @@
1
- import type { Entry, EntrySkeletonType, EntryFieldTypes, EntryCollection } from 'contentful/dist/types';
2
- import * as contentful from 'contentful';
1
+ import type { Entry, EntrySkeletonType, EntryFieldTypes, EntryCollection, ContentfulClientApi } from 'contentful/dist/types';
3
2
  export type MessageTemplate = EntrySkeletonType & {
4
3
  contentTypeId: 'messageTemplate';
5
4
  fields: {
@@ -20,7 +19,7 @@ export type MessageTemplate = EntrySkeletonType & {
20
19
  * If these are not set, a warning will be logged.
21
20
  **/
22
21
  export declare class ContentfulService {
23
- protected readonly contentfulClient: contentful.ContentfulClientApi<undefined>;
22
+ protected readonly contentfulClient: ContentfulClientApi<undefined> | undefined;
24
23
  /**
25
24
  * This contructs the ContentfulService. The following environment variables
26
25
  * must be set:
@@ -50,6 +50,9 @@ class ContentfulService {
50
50
  return messageTemplates;
51
51
  };
52
52
  this.getContentfulEntries = async (contentType, include) => {
53
+ if (!this.contentfulClient) {
54
+ throw new Error('Contenful client not initialized because of missing configurations: CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
55
+ }
53
56
  const entries = await this.contentfulClient.getEntries({
54
57
  content_type: contentType,
55
58
  ...(include ? { include } : {}),
@@ -57,16 +60,21 @@ class ContentfulService {
57
60
  return entries;
58
61
  };
59
62
  this.getContentfulEntry = async (entryId) => {
63
+ if (!this.contentfulClient) {
64
+ throw new Error('Contenful client not initialized because of missing configurations: CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
65
+ }
60
66
  const entry = await this.contentfulClient.getEntry(entryId);
61
67
  return entry;
62
68
  };
63
69
  if (!process.env.CONTENTFUL_SPACE_ID || !process.env.CONTENTFUL_ACCESS_TOKEN) {
64
70
  console.warn('CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
65
71
  }
66
- this.contentfulClient = contentful.createClient({
67
- space: process.env.CONTENTFUL_SPACE_ID || '',
68
- accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || '',
69
- });
72
+ else {
73
+ this.contentfulClient = contentful.createClient({
74
+ space: process.env.CONTENTFUL_SPACE_ID || '',
75
+ accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || '',
76
+ });
77
+ }
70
78
  }
71
79
  }
72
80
  exports.ContentfulService = ContentfulService;
@@ -1 +1 @@
1
- {"version":3,"file":"contentful.service.js","sourceRoot":"","sources":["../../../src/services/contentful.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uDAAyC;AAYzC;;;;;;;;;IASI;AACJ,MAAa,iBAAiB;IAE5B;;;;;;;OAOG;IACH;QAWA,wBAAmB,GAAG,KAAK,IAA+C,EAAE;YAC1E,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAkB,iBAAiB,EAAE,CAAC,CAAC,CAAC;YAChG,OAAO,gBAAgB,CAAC;QAC1B,CAAC,CAAC;QAEF,yBAAoB,GAAG,KAAK,EAA+B,WAAmB,EAAE,OAAgB,EAA+B,EAAE;YAC/H,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAI;gBACxD,YAAY,EAAE,WAAW;gBACzB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9B,CAAC,CAAC;YACH,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;QAEF,uBAAkB,GAAG,KAAK,EAA+B,OAAe,EAAqB,EAAE;YAC7F,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAI,OAAO,CAAC,CAAC;YAC/D,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QA1BA,IAAI,CAAC,OAAO,CAAC,GAA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AAgB,EAAE;gBAC1B,MAAM,IAAI,KAAK,CAAC,oJAAoJ,CAAC,CAAC;aACvK;YACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAI,OAAO,CAAC,CAAC;YAC/D,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QAhCA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE;YAC5E,OAAO,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;SAChG;aAAM;YACL,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,YAAY,CAAC;gBAC9C,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,EAAE;gBAC5C,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,EAAE;aACvD,CAAC,CAAC;SACJ;IACH,CAAC;CAyBF;AA5CD,8CA4CC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampsec/platform-client",
3
- "version": "55.7.0",
3
+ "version": "55.7.1",
4
4
  "description": "",
5
5
  "main": "build/src/index.js",
6
6
  "runkitExampleFilename": "example/main.js",
@@ -1,4 +1,4 @@
1
- import type {Entry, EntrySkeletonType, EntryFieldTypes, EntryCollection} from 'contentful/dist/types';
1
+ import type {Entry, EntrySkeletonType, EntryFieldTypes, EntryCollection, ContentfulClientApi} from 'contentful/dist/types';
2
2
  import * as contentful from 'contentful';
3
3
 
4
4
  export type MessageTemplate = EntrySkeletonType & {
@@ -22,7 +22,7 @@ export type MessageTemplate = EntrySkeletonType & {
22
22
  * If these are not set, a warning will be logged.
23
23
  **/
24
24
  export class ContentfulService {
25
- protected readonly contentfulClient;
25
+ protected readonly contentfulClient: ContentfulClientApi<undefined> | undefined;
26
26
  /**
27
27
  * This contructs the ContentfulService. The following environment variables
28
28
  * must be set:
@@ -34,12 +34,12 @@ export class ContentfulService {
34
34
  constructor() {
35
35
  if (!process.env.CONTENTFUL_SPACE_ID || !process.env.CONTENTFUL_ACCESS_TOKEN) {
36
36
  console.warn('CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
37
+ } else {
38
+ this.contentfulClient = contentful.createClient({
39
+ space: process.env.CONTENTFUL_SPACE_ID || '',
40
+ accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || '',
41
+ });
37
42
  }
38
-
39
- this.contentfulClient = contentful.createClient({
40
- space: process.env.CONTENTFUL_SPACE_ID || '',
41
- accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || '',
42
- });
43
43
  }
44
44
 
45
45
  getMessageTemplates = async (): Promise<EntryCollection<MessageTemplate>> => {
@@ -48,6 +48,9 @@ export class ContentfulService {
48
48
  };
49
49
 
50
50
  getContentfulEntries = async <T extends EntrySkeletonType>(contentType: string, include?: number): Promise<EntryCollection<T>> => {
51
+ if (!this.contentfulClient) {
52
+ throw new Error('Contenful client not initialized because of missing configurations: CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
53
+ }
51
54
  const entries = await this.contentfulClient.getEntries<T>({
52
55
  content_type: contentType,
53
56
  ...(include ? {include} : {}),
@@ -56,6 +59,9 @@ export class ContentfulService {
56
59
  };
57
60
 
58
61
  getContentfulEntry = async <T extends EntrySkeletonType>(entryId: string): Promise<Entry<T>> => {
62
+ if (!this.contentfulClient) {
63
+ throw new Error('Contenful client not initialized because of missing configurations: CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
64
+ }
59
65
  const entry = await this.contentfulClient.getEntry<T>(entryId);
60
66
  return entry;
61
67
  };