Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): accept null in optional catalog fields

Yudhi Armyndharis498fe098c810
diff --git a/src/modules/plugins/catalog.spec.ts b/src/modules/plugins/catalog.spec.ts
index 91071d650..f612359c9 100644
--- a/src/modules/plugins/catalog.spec.ts
+++ b/src/modules/plugins/catalog.spec.ts
@@ -73,6 +73,10 @@ describe('isCatalogEntry', () => {
);
});
+ it('treats a null optional field as absent', () => {
+ expect(isCatalogEntry({ ...ok, homepage: null, testedOpenWAVersion: null, keywords: null })).toBe(true);
+ });
+
it.each([
null,
5,
diff --git a/src/modules/plugins/catalog.ts b/src/modules/plugins/catalog.ts
index b7caf8c08..81739fd4a 100644
--- a/src/modules/plugins/catalog.ts
+++ b/src/modules/plugins/catalog.ts
@@ -37,7 +37,8 @@ const OPTIONAL_STRING_FIELDS = [
/**
* Whether `value` has the shape of {@link CatalogEntry}: non-empty string id, name and version, string
- * optional fields, and a string-array `keywords`. Extra fields are tolerated. The dashboard lists and
+ * optional fields, and a string-array `keywords`; a null optional field counts as absent, as a hand-written
+ * catalog often has it. Extra fields are tolerated. The dashboard lists and
* searches these fields as text, so a value of another type would break the page that renders them.
*/
export function isCatalogEntry(value: unknown): value is CatalogEntry {
@@ -48,8 +49,8 @@ export function isCatalogEntry(value: unknown): value is CatalogEntry {
text(entry.id) &&
text(entry.name) &&
text(entry.version) &&
- OPTIONAL_STRING_FIELDS.every(key => entry[key] === undefined || typeof entry[key] === 'string') &&
- (entry.keywords === undefined ||
+ OPTIONAL_STRING_FIELDS.every(key => entry[key] == null || typeof entry[key] === 'string') &&
+ (entry.keywords == null ||
(Array.isArray(entry.keywords) && entry.keywords.every(word => typeof word === 'string')))
);
}
diff --git a/src/modules/plugins/plugins.service.spec.ts b/src/modules/plugins/plugins.service.spec.ts
index 28de61350..1b014c269 100644
--- a/src/modules/plugins/plugins.service.spec.ts
+++ b/src/modules/plugins/plugins.service.spec.ts
@@ -1212,6 +1212,11 @@ describe('PluginsService remote catalog', () => {
await expect(service().getCatalog()).resolves.toMatchObject([{ id: 'a', stars: 5, keywords: ['x'] }]);
});
+ it('accepts null in optional fields', async () => {
+ serveOnce('[{"id":"a","name":"A","version":"1.0.0","homepage":null,"keywords":null}]');
+ await expect(service().getCatalog()).resolves.toMatchObject([{ id: 'a', installed: false }]);
+ });
+
it('annotates a well-formed catalog', async () => {
serveOnce('[{"id":"a","name":"A","version":"1.0.0"}]');
await expect(service().getCatalog()).resolves.toEqual([