@mobilizehub/payload-plugin 0.0.1 → 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/dist/access/authenticated.d.ts +4 -0
- package/dist/access/authenticated.js +5 -0
- package/dist/access/authenticated.js.map +1 -0
- package/dist/access/authenticated.spec.d.ts +1 -0
- package/dist/access/authenticated.spec.js +33 -0
- package/dist/access/authenticated.spec.js.map +1 -0
- package/dist/collections/contacts/generateContactsCollection.d.ts +22 -0
- package/dist/collections/contacts/generateContactsCollection.js +124 -0
- package/dist/collections/contacts/generateContactsCollection.js.map +1 -0
- package/dist/collections/tags/generateTagsCollection.d.ts +3 -0
- package/dist/collections/tags/generateTagsCollection.js +29 -0
- package/dist/collections/tags/generateTagsCollection.js.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/access/authenticated.ts"],"sourcesContent":["import type { AccessArgs, User } from 'payload'\n\ntype IsAuthenticated = (args: AccessArgs<User>) => boolean\n\nexport const authenticated: IsAuthenticated = ({ req: { user } }) => {\n return Boolean(user)\n}\n"],"names":["authenticated","req","user","Boolean"],"mappings":"AAIA,OAAO,MAAMA,gBAAiC,CAAC,EAAEC,KAAK,EAAEC,IAAI,EAAE,EAAE;IAC9D,OAAOC,QAAQD;AACjB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { authenticated } from './authenticated.js';
|
|
3
|
+
describe('authenticated', ()=>{
|
|
4
|
+
it('returns true when user exists', ()=>{
|
|
5
|
+
const args = {
|
|
6
|
+
req: {
|
|
7
|
+
user: {
|
|
8
|
+
id: '123',
|
|
9
|
+
email: 'test@example.com'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
expect(authenticated(args)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
it('returns false when user is null', ()=>{
|
|
16
|
+
const args = {
|
|
17
|
+
req: {
|
|
18
|
+
user: null
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
expect(authenticated(args)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
it('returns false when user is undefined', ()=>{
|
|
24
|
+
const args = {
|
|
25
|
+
req: {
|
|
26
|
+
user: undefined
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
expect(authenticated(args)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=authenticated.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/access/authenticated.spec.ts"],"sourcesContent":["import type { AccessArgs, User } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { authenticated } from './authenticated.js'\n\ndescribe('authenticated', () => {\n it('returns true when user exists', () => {\n const args = {\n req: { user: { id: '123', email: 'test@example.com' } },\n } as AccessArgs<User>\n\n expect(authenticated(args)).toBe(true)\n })\n\n it('returns false when user is null', () => {\n const args = {\n req: { user: null },\n } as unknown as AccessArgs<User>\n\n expect(authenticated(args)).toBe(false)\n })\n\n it('returns false when user is undefined', () => {\n const args = {\n req: { user: undefined },\n } as unknown as AccessArgs<User>\n\n expect(authenticated(args)).toBe(false)\n })\n})\n"],"names":["describe","expect","it","authenticated","args","req","user","id","email","toBe","undefined"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,aAAa,QAAQ,qBAAoB;AAElDH,SAAS,iBAAiB;IACxBE,GAAG,iCAAiC;QAClC,MAAME,OAAO;YACXC,KAAK;gBAAEC,MAAM;oBAAEC,IAAI;oBAAOC,OAAO;gBAAmB;YAAE;QACxD;QAEAP,OAAOE,cAAcC,OAAOK,IAAI,CAAC;IACnC;IAEAP,GAAG,mCAAmC;QACpC,MAAME,OAAO;YACXC,KAAK;gBAAEC,MAAM;YAAK;QACpB;QAEAL,OAAOE,cAAcC,OAAOK,IAAI,CAAC;IACnC;IAEAP,GAAG,wCAAwC;QACzC,MAAME,OAAO;YACXC,KAAK;gBAAEC,MAAMI;YAAU;QACzB;QAEAT,OAAOE,cAAcC,OAAOK,IAAI,CAAC;IACnC;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { MobilizehubPluginConfig } from '../../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates the contacts collection configuration.
|
|
5
|
+
* @param contactsConfig
|
|
6
|
+
* @returns CollectionConfig
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { generateContactsCollection } from 'path/to/generateContactsCollection';
|
|
11
|
+
*
|
|
12
|
+
* const contactsCollection = generateContactsCollection({
|
|
13
|
+
* contactsOverrides: {
|
|
14
|
+
* slug: 'my-contacts',
|
|
15
|
+
* admin: {
|
|
16
|
+
* useAsTitle: 'firstName',
|
|
17
|
+
* },
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const generateContactsCollection: (contactsConfig: Pick<MobilizehubPluginConfig, "contactsOverrides">) => CollectionConfig;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import iso from 'i18n-iso-countries';
|
|
2
|
+
import { authenticated } from '../../access/authenticated.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates country options for the country select field.
|
|
5
|
+
*/ const countryOptions = Object.entries(iso.getNames('en', {
|
|
6
|
+
select: 'official'
|
|
7
|
+
})).map(([code, name])=>({
|
|
8
|
+
label: name,
|
|
9
|
+
value: code
|
|
10
|
+
}));
|
|
11
|
+
/**
|
|
12
|
+
* Generates the contacts collection configuration.
|
|
13
|
+
* @param contactsConfig
|
|
14
|
+
* @returns CollectionConfig
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { generateContactsCollection } from 'path/to/generateContactsCollection';
|
|
19
|
+
*
|
|
20
|
+
* const contactsCollection = generateContactsCollection({
|
|
21
|
+
* contactsOverrides: {
|
|
22
|
+
* slug: 'my-contacts',
|
|
23
|
+
* admin: {
|
|
24
|
+
* useAsTitle: 'firstName',
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/ export const generateContactsCollection = (contactsConfig)=>{
|
|
30
|
+
const defaultFields = [
|
|
31
|
+
{
|
|
32
|
+
name: 'tags',
|
|
33
|
+
type: 'relationship',
|
|
34
|
+
admin: {
|
|
35
|
+
position: 'sidebar'
|
|
36
|
+
},
|
|
37
|
+
hasMany: true,
|
|
38
|
+
relationTo: 'tags'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: 'tabs',
|
|
42
|
+
tabs: [
|
|
43
|
+
{
|
|
44
|
+
fields: [
|
|
45
|
+
{
|
|
46
|
+
name: 'email',
|
|
47
|
+
type: 'email',
|
|
48
|
+
required: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'emailOptIn',
|
|
52
|
+
type: 'checkbox',
|
|
53
|
+
defaultValue: false,
|
|
54
|
+
label: 'Receive emails'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'firstName',
|
|
58
|
+
type: 'text'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'lastName',
|
|
62
|
+
type: 'text'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'mobileNumber',
|
|
66
|
+
type: 'text'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'mobileOptIn',
|
|
70
|
+
type: 'checkbox',
|
|
71
|
+
defaultValue: false,
|
|
72
|
+
label: 'Receive sms'
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
label: 'Details'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
fields: [
|
|
79
|
+
{
|
|
80
|
+
name: 'address',
|
|
81
|
+
type: 'text'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'city',
|
|
85
|
+
type: 'text'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'state',
|
|
89
|
+
type: 'text'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'zip',
|
|
93
|
+
type: 'text'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'country',
|
|
97
|
+
type: 'select',
|
|
98
|
+
options: countryOptions
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
label: 'Location'
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
const config = {
|
|
107
|
+
...contactsConfig?.contactsOverrides || {},
|
|
108
|
+
slug: contactsConfig.contactsOverrides?.slug || 'contacts',
|
|
109
|
+
access: {
|
|
110
|
+
read: authenticated,
|
|
111
|
+
...contactsConfig?.contactsOverrides?.access || {}
|
|
112
|
+
},
|
|
113
|
+
admin: {
|
|
114
|
+
useAsTitle: contactsConfig?.contactsOverrides?.admin?.useAsTitle || 'email',
|
|
115
|
+
...contactsConfig?.contactsOverrides?.admin || {}
|
|
116
|
+
},
|
|
117
|
+
fields: contactsConfig.contactsOverrides?.fields ? contactsConfig.contactsOverrides.fields({
|
|
118
|
+
defaultFields
|
|
119
|
+
}) : defaultFields
|
|
120
|
+
};
|
|
121
|
+
return config;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=generateContactsCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/contacts/generateContactsCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport iso from 'i18n-iso-countries'\n\nimport type { MobilizehubPluginConfig } from '../../types/index.js'\n\nimport { authenticated } from '../../access/authenticated.js'\n\n/**\n * Generates country options for the country select field.\n */\nconst countryOptions = Object.entries(iso.getNames('en', { select: 'official' })).map(\n ([code, name]) => ({\n label: name,\n value: code,\n }),\n)\n\n/**\n * Generates the contacts collection configuration.\n * @param contactsConfig\n * @returns CollectionConfig\n *\n * @example\n * ```ts\n * import { generateContactsCollection } from 'path/to/generateContactsCollection';\n *\n * const contactsCollection = generateContactsCollection({\n * contactsOverrides: {\n * slug: 'my-contacts',\n * admin: {\n * useAsTitle: 'firstName',\n * },\n * },\n * });\n * ```\n */\nexport const generateContactsCollection = (\n contactsConfig: Pick<MobilizehubPluginConfig, 'contactsOverrides'>,\n): CollectionConfig => {\n const defaultFields: Field[] = [\n {\n name: 'tags',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n },\n hasMany: true,\n relationTo: 'tags',\n },\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'email',\n type: 'email',\n required: true,\n },\n {\n name: 'emailOptIn',\n type: 'checkbox',\n defaultValue: false,\n label: 'Receive emails',\n },\n {\n name: 'firstName',\n type: 'text',\n },\n {\n name: 'lastName',\n type: 'text',\n },\n {\n name: 'mobileNumber',\n type: 'text',\n },\n {\n name: 'mobileOptIn',\n type: 'checkbox',\n defaultValue: false,\n label: 'Receive sms',\n },\n ],\n label: 'Details',\n },\n {\n fields: [\n {\n name: 'address',\n type: 'text',\n },\n {\n name: 'city',\n type: 'text',\n },\n {\n name: 'state',\n type: 'text',\n },\n {\n name: 'zip',\n type: 'text',\n },\n {\n name: 'country',\n type: 'select',\n options: countryOptions,\n },\n ],\n label: 'Location',\n },\n /**\n * @todo Enable form submissions relationship when form submissions collection is available.\n */\n // {\n // fields: [\n // {\n // name: 'formSubmissions',\n // type: 'join',\n // admin: {\n // description: 'Form submissions made by this contact',\n // },\n // collection: 'formSubmissions',\n // on: 'contact',\n // },\n // ],\n // label: 'Submissions',\n // },\n /**\n * @todo Enable transactions relationship when transactions collection is available.\n */\n // {\n // fields: [\n // {\n // name: 'transactions',\n // type: 'join',\n // admin: {\n // description: 'Transactions made by this contact',\n // },\n // collection: 'transactions',\n // on: 'contact',\n // },\n // ],\n // label: 'Transactions',\n // },\n ],\n },\n ]\n\n const config: CollectionConfig = {\n ...(contactsConfig?.contactsOverrides || {}),\n slug: contactsConfig.contactsOverrides?.slug || 'contacts',\n access: {\n read: authenticated,\n ...(contactsConfig?.contactsOverrides?.access || {}),\n },\n admin: {\n useAsTitle: contactsConfig?.contactsOverrides?.admin?.useAsTitle || 'email',\n ...(contactsConfig?.contactsOverrides?.admin || {}),\n },\n fields: contactsConfig.contactsOverrides?.fields\n ? contactsConfig.contactsOverrides.fields({ defaultFields })\n : defaultFields,\n }\n return config\n}\n"],"names":["iso","authenticated","countryOptions","Object","entries","getNames","select","map","code","name","label","value","generateContactsCollection","contactsConfig","defaultFields","type","admin","position","hasMany","relationTo","tabs","fields","required","defaultValue","options","config","contactsOverrides","slug","access","read","useAsTitle"],"mappings":"AAEA,OAAOA,SAAS,qBAAoB;AAIpC,SAASC,aAAa,QAAQ,gCAA+B;AAE7D;;CAEC,GACD,MAAMC,iBAAiBC,OAAOC,OAAO,CAACJ,IAAIK,QAAQ,CAAC,MAAM;IAAEC,QAAQ;AAAW,IAAIC,GAAG,CACnF,CAAC,CAACC,MAAMC,KAAK,GAAM,CAAA;QACjBC,OAAOD;QACPE,OAAOH;IACT,CAAA;AAGF;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,MAAMI,6BAA6B,CACxCC;IAEA,MAAMC,gBAAyB;QAC7B;YACEL,MAAM;YACNM,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,SAAS;YACTC,YAAY;QACd;QACA;YACEJ,MAAM;YACNK,MAAM;gBACJ;oBACEC,QAAQ;wBACN;4BACEZ,MAAM;4BACNM,MAAM;4BACNO,UAAU;wBACZ;wBACA;4BACEb,MAAM;4BACNM,MAAM;4BACNQ,cAAc;4BACdb,OAAO;wBACT;wBACA;4BACED,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;4BACNQ,cAAc;4BACdb,OAAO;wBACT;qBACD;oBACDA,OAAO;gBACT;gBACA;oBACEW,QAAQ;wBACN;4BACEZ,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;wBACR;wBACA;4BACEN,MAAM;4BACNM,MAAM;4BACNS,SAAStB;wBACX;qBACD;oBACDQ,OAAO;gBACT;aAmCD;QACH;KACD;IAED,MAAMe,SAA2B;QAC/B,GAAIZ,gBAAgBa,qBAAqB,CAAC,CAAC;QAC3CC,MAAMd,eAAea,iBAAiB,EAAEC,QAAQ;QAChDC,QAAQ;YACNC,MAAM5B;YACN,GAAIY,gBAAgBa,mBAAmBE,UAAU,CAAC,CAAC;QACrD;QACAZ,OAAO;YACLc,YAAYjB,gBAAgBa,mBAAmBV,OAAOc,cAAc;YACpE,GAAIjB,gBAAgBa,mBAAmBV,SAAS,CAAC,CAAC;QACpD;QACAK,QAAQR,eAAea,iBAAiB,EAAEL,SACtCR,eAAea,iBAAiB,CAACL,MAAM,CAAC;YAAEP;QAAc,KACxDA;IACN;IACA,OAAOW;AACT,EAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { authenticated } from '../../access/authenticated.js';
|
|
2
|
+
export const generateTagsCollection = (tagsConfig)=>{
|
|
3
|
+
const defaultFields = [
|
|
4
|
+
{
|
|
5
|
+
name: 'name',
|
|
6
|
+
type: 'text',
|
|
7
|
+
required: true
|
|
8
|
+
}
|
|
9
|
+
];
|
|
10
|
+
const config = {
|
|
11
|
+
...tagsConfig.tagsOverrides,
|
|
12
|
+
slug: tagsConfig.tagsOverrides?.slug || 'tags',
|
|
13
|
+
access: {
|
|
14
|
+
read: authenticated,
|
|
15
|
+
...tagsConfig.tagsOverrides?.access || {}
|
|
16
|
+
},
|
|
17
|
+
admin: {
|
|
18
|
+
...tagsConfig.tagsOverrides?.admin || {},
|
|
19
|
+
hidden: tagsConfig.tagsOverrides?.admin?.hidden || true,
|
|
20
|
+
useAsTitle: tagsConfig.tagsOverrides?.admin?.useAsTitle || 'name'
|
|
21
|
+
},
|
|
22
|
+
fields: tagsConfig.tagsOverrides?.fields ? tagsConfig.tagsOverrides.fields({
|
|
23
|
+
defaultFields
|
|
24
|
+
}) : defaultFields
|
|
25
|
+
};
|
|
26
|
+
return config;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=generateTagsCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/tags/generateTagsCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { MobilizehubPluginConfig } from '../../types/index.js'\n\nimport { authenticated } from '../../access/authenticated.js'\n\nexport const generateTagsCollection = (\n tagsConfig: Pick<MobilizehubPluginConfig, 'tagsOverrides'>,\n): CollectionConfig => {\n const defaultFields: Field[] = [\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n ]\n\n const config: CollectionConfig = {\n ...tagsConfig.tagsOverrides,\n slug: tagsConfig.tagsOverrides?.slug || 'tags',\n access: {\n read: authenticated,\n ...(tagsConfig.tagsOverrides?.access || {}),\n },\n admin: {\n ...(tagsConfig.tagsOverrides?.admin || {}),\n hidden: tagsConfig.tagsOverrides?.admin?.hidden || true,\n useAsTitle: tagsConfig.tagsOverrides?.admin?.useAsTitle || 'name',\n },\n fields: tagsConfig.tagsOverrides?.fields\n ? tagsConfig.tagsOverrides.fields({ defaultFields })\n : defaultFields,\n }\n\n return config\n}\n"],"names":["authenticated","generateTagsCollection","tagsConfig","defaultFields","name","type","required","config","tagsOverrides","slug","access","read","admin","hidden","useAsTitle","fields"],"mappings":"AAIA,SAASA,aAAa,QAAQ,gCAA+B;AAE7D,OAAO,MAAMC,yBAAyB,CACpCC;IAEA,MAAMC,gBAAyB;QAC7B;YACEC,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;KACD;IAED,MAAMC,SAA2B;QAC/B,GAAGL,WAAWM,aAAa;QAC3BC,MAAMP,WAAWM,aAAa,EAAEC,QAAQ;QACxCC,QAAQ;YACNC,MAAMX;YACN,GAAIE,WAAWM,aAAa,EAAEE,UAAU,CAAC,CAAC;QAC5C;QACAE,OAAO;YACL,GAAIV,WAAWM,aAAa,EAAEI,SAAS,CAAC,CAAC;YACzCC,QAAQX,WAAWM,aAAa,EAAEI,OAAOC,UAAU;YACnDC,YAAYZ,WAAWM,aAAa,EAAEI,OAAOE,cAAc;QAC7D;QACAC,QAAQb,WAAWM,aAAa,EAAEO,SAC9Bb,WAAWM,aAAa,CAACO,MAAM,CAAC;YAAEZ;QAAc,KAChDA;IACN;IAEA,OAAOI;AACT,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Config } from 'payload';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
import type { MobilizehubPluginConfig } from './types/index.js';
|
|
3
|
+
export * from './types/index.js';
|
|
5
4
|
export declare const mobilizehubPlugin: (pluginOptions: MobilizehubPluginConfig) => (config: Config) => Config;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { generateContactsCollection } from './collections/contacts/generateContactsCollection.js';
|
|
2
|
+
import { generateTagsCollection } from './collections/tags/generateTagsCollection.js';
|
|
3
|
+
export * from './types/index.js';
|
|
1
4
|
export const mobilizehubPlugin = (pluginOptions)=>(config)=>{
|
|
2
5
|
if (!config.collections) {
|
|
3
6
|
config.collections = [];
|
|
4
7
|
}
|
|
8
|
+
config.collections.push(generateTagsCollection(pluginOptions), generateContactsCollection(pluginOptions));
|
|
5
9
|
if (pluginOptions.disabled) {
|
|
6
10
|
return config;
|
|
7
11
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { MobilizehubPluginConfig } from './types/index.js'\n\nimport { generateContactsCollection } from './collections/contacts/generateContactsCollection.js'\nimport { generateTagsCollection } from './collections/tags/generateTagsCollection.js'\n\nexport * from './types/index.js'\n\nexport const mobilizehubPlugin =\n (pluginOptions: MobilizehubPluginConfig) =>\n (config: Config): Config => {\n if (!config.collections) {\n config.collections = []\n }\n\n config.collections.push(\n generateTagsCollection(pluginOptions),\n generateContactsCollection(pluginOptions),\n )\n\n if (pluginOptions.disabled) {\n return config\n }\n\n const incomingOnInit = config.onInit\n\n config.onInit = async (payload) => {\n if (incomingOnInit) {\n await incomingOnInit(payload)\n }\n }\n\n return config\n }\n"],"names":["generateContactsCollection","generateTagsCollection","mobilizehubPlugin","pluginOptions","config","collections","push","disabled","incomingOnInit","onInit","payload"],"mappings":"AAIA,SAASA,0BAA0B,QAAQ,uDAAsD;AACjG,SAASC,sBAAsB,QAAQ,+CAA8C;AAErF,cAAc,mBAAkB;AAEhC,OAAO,MAAMC,oBACX,CAACC,gBACD,CAACC;QACC,IAAI,CAACA,OAAOC,WAAW,EAAE;YACvBD,OAAOC,WAAW,GAAG,EAAE;QACzB;QAEAD,OAAOC,WAAW,CAACC,IAAI,CACrBL,uBAAuBE,gBACvBH,2BAA2BG;QAG7B,IAAIA,cAAcI,QAAQ,EAAE;YAC1B,OAAOH;QACT;QAEA,MAAMI,iBAAiBJ,OAAOK,MAAM;QAEpCL,OAAOK,MAAM,GAAG,OAAOC;YACrB,IAAIF,gBAAgB;gBAClB,MAAMA,eAAeE;YACvB;QACF;QAEA,OAAON;IACT,EAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CollectionConfig, Field } from 'payload';
|
|
2
|
+
export type FieldsOverride = (args: {
|
|
3
|
+
defaultFields: Field[];
|
|
4
|
+
}) => Field[];
|
|
5
|
+
export type CollectionOverride = {
|
|
6
|
+
fields?: FieldsOverride;
|
|
7
|
+
} & Partial<Omit<CollectionConfig, 'fields'>>;
|
|
8
|
+
export type MobilizehubPluginConfig = {
|
|
9
|
+
contactsOverrides?: CollectionOverride;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
tagsOverrides?: CollectionOverride;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nexport type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]\n\nexport type CollectionOverride = { fields?: FieldsOverride } & Partial<\n Omit<CollectionConfig, 'fields'>\n>\nexport type MobilizehubPluginConfig = {\n contactsOverrides?: CollectionOverride\n disabled?: boolean\n tagsOverrides?: CollectionOverride\n}\n"],"names":[],"mappings":"AAOA,WAIC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilizehub/payload-plugin",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Edvocacy plugin for Payload",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"type": "module",
|
|
@@ -70,6 +70,9 @@
|
|
|
70
70
|
"pnpm": "^9 || ^10"
|
|
71
71
|
},
|
|
72
72
|
"registry": "https://registry.npmjs.org/",
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"i18n-iso-countries": "^7.14.0"
|
|
75
|
+
},
|
|
73
76
|
"scripts": {
|
|
74
77
|
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
75
78
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
@@ -79,9 +82,11 @@
|
|
|
79
82
|
"dev": "next dev dev --turbo",
|
|
80
83
|
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
81
84
|
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
85
|
+
"dev:generate": "pnpm dev:generate-importmap && pnpm dev:generate-types",
|
|
82
86
|
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
83
87
|
"generate:importmap": "pnpm dev:generate-importmap",
|
|
84
88
|
"generate:types": "pnpm dev:generate-types",
|
|
89
|
+
"generate": "pnpm generate:importmap && pnpm generate:types",
|
|
85
90
|
"lint": "eslint",
|
|
86
91
|
"lint:fix": "eslint ./src --fix",
|
|
87
92
|
"test": "pnpm test:int && pnpm test:e2e",
|