@mobilizehub/payload-plugin 0.0.0 → 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/exports/client.d.ts +1 -1
- package/dist/exports/client.js +0 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/rsc.d.ts +1 -1
- package/dist/exports/rsc.js +0 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/index.d.ts +4 -9
- package/dist/index.js +6 -65
- 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
- package/dist/components/BeforeDashboardClient.d.ts +0 -1
- package/dist/components/BeforeDashboardClient.js +0 -36
- package/dist/components/BeforeDashboardClient.js.map +0 -1
- package/dist/components/BeforeDashboardServer.d.ts +0 -2
- package/dist/components/BeforeDashboardServer.js +0 -22
- package/dist/components/BeforeDashboardServer.js.map +0 -1
- package/dist/components/BeforeDashboardServer.module.css +0 -5
- package/dist/endpoints/customEndpointHandler.d.ts +0 -2
- package/dist/endpoints/customEndpointHandler.js +0 -7
- package/dist/endpoints/customEndpointHandler.js.map +0 -1
|
@@ -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/exports/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/exports/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"names":[],"mappings":""}
|
package/dist/exports/rsc.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/exports/rsc.js
CHANGED
package/dist/exports/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/rsc.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
collections?: Partial<Record<CollectionSlug, true>>;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare const payloadPlugin: (pluginOptions: PayloadPluginConfig) => (config: Config) => Config;
|
|
1
|
+
import type { Config } from 'payload';
|
|
2
|
+
import type { MobilizehubPluginConfig } from './types/index.js';
|
|
3
|
+
export * from './types/index.js';
|
|
4
|
+
export declare const mobilizehubPlugin: (pluginOptions: MobilizehubPluginConfig) => (config: Config) => Config;
|
package/dist/index.js
CHANGED
|
@@ -1,78 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { generateContactsCollection } from './collections/contacts/generateContactsCollection.js';
|
|
2
|
+
import { generateTagsCollection } from './collections/tags/generateTagsCollection.js';
|
|
3
|
+
export * from './types/index.js';
|
|
4
|
+
export const mobilizehubPlugin = (pluginOptions)=>(config)=>{
|
|
3
5
|
if (!config.collections) {
|
|
4
6
|
config.collections = [];
|
|
5
7
|
}
|
|
6
|
-
config.collections.push(
|
|
7
|
-
|
|
8
|
-
fields: [
|
|
9
|
-
{
|
|
10
|
-
name: 'id',
|
|
11
|
-
type: 'text'
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
});
|
|
15
|
-
if (pluginOptions.collections) {
|
|
16
|
-
for(const collectionSlug in pluginOptions.collections){
|
|
17
|
-
const collection = config.collections.find((collection)=>collection.slug === collectionSlug);
|
|
18
|
-
if (collection) {
|
|
19
|
-
collection.fields.push({
|
|
20
|
-
name: 'addedByPlugin',
|
|
21
|
-
type: 'text',
|
|
22
|
-
admin: {
|
|
23
|
-
position: 'sidebar'
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.
|
|
31
|
-
* If your plugin heavily modifies the database schema, you may want to remove this property.
|
|
32
|
-
*/ if (pluginOptions.disabled) {
|
|
8
|
+
config.collections.push(generateTagsCollection(pluginOptions), generateContactsCollection(pluginOptions));
|
|
9
|
+
if (pluginOptions.disabled) {
|
|
33
10
|
return config;
|
|
34
11
|
}
|
|
35
|
-
if (!config.endpoints) {
|
|
36
|
-
config.endpoints = [];
|
|
37
|
-
}
|
|
38
|
-
if (!config.admin) {
|
|
39
|
-
config.admin = {};
|
|
40
|
-
}
|
|
41
|
-
if (!config.admin.components) {
|
|
42
|
-
config.admin.components = {};
|
|
43
|
-
}
|
|
44
|
-
if (!config.admin.components.beforeDashboard) {
|
|
45
|
-
config.admin.components.beforeDashboard = [];
|
|
46
|
-
}
|
|
47
|
-
config.admin.components.beforeDashboard.push(`payload-plugin/client#BeforeDashboardClient`);
|
|
48
|
-
config.admin.components.beforeDashboard.push(`payload-plugin/rsc#BeforeDashboardServer`);
|
|
49
|
-
config.endpoints.push({
|
|
50
|
-
handler: customEndpointHandler,
|
|
51
|
-
method: 'get',
|
|
52
|
-
path: '/my-plugin-endpoint'
|
|
53
|
-
});
|
|
54
12
|
const incomingOnInit = config.onInit;
|
|
55
13
|
config.onInit = async (payload)=>{
|
|
56
|
-
// Ensure we are executing any existing onInit functions before running our own.
|
|
57
14
|
if (incomingOnInit) {
|
|
58
15
|
await incomingOnInit(payload);
|
|
59
16
|
}
|
|
60
|
-
const { totalDocs } = await payload.count({
|
|
61
|
-
collection: 'plugin-collection',
|
|
62
|
-
where: {
|
|
63
|
-
id: {
|
|
64
|
-
equals: 'seeded-by-plugin'
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
if (totalDocs === 0) {
|
|
69
|
-
await payload.create({
|
|
70
|
-
collection: 'plugin-collection',
|
|
71
|
-
data: {
|
|
72
|
-
id: 'seeded-by-plugin'
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
17
|
};
|
|
77
18
|
return config;
|
|
78
19
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {
|
|
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.
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const BeforeDashboardClient: () => import("react").JSX.Element;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useConfig } from '@payloadcms/ui';
|
|
4
|
-
import { useEffect, useState } from 'react';
|
|
5
|
-
export const BeforeDashboardClient = ()=>{
|
|
6
|
-
const { config } = useConfig();
|
|
7
|
-
const [message, setMessage] = useState('');
|
|
8
|
-
useEffect(()=>{
|
|
9
|
-
const fetchMessage = async ()=>{
|
|
10
|
-
const response = await fetch(`${config.serverURL}${config.routes.api}/my-plugin-endpoint`);
|
|
11
|
-
const result = await response.json();
|
|
12
|
-
setMessage(result.message);
|
|
13
|
-
};
|
|
14
|
-
void fetchMessage();
|
|
15
|
-
}, [
|
|
16
|
-
config.serverURL,
|
|
17
|
-
config.routes.api
|
|
18
|
-
]);
|
|
19
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
20
|
-
children: [
|
|
21
|
-
/*#__PURE__*/ _jsx("h1", {
|
|
22
|
-
children: "Added by the plugin: Before Dashboard Client"
|
|
23
|
-
}),
|
|
24
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
25
|
-
children: [
|
|
26
|
-
"Message from the endpoint:",
|
|
27
|
-
/*#__PURE__*/ _jsx("div", {
|
|
28
|
-
children: message || 'Loading...'
|
|
29
|
-
})
|
|
30
|
-
]
|
|
31
|
-
})
|
|
32
|
-
]
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=BeforeDashboardClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/BeforeDashboardClient.tsx"],"sourcesContent":["'use client'\nimport { useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\n\nexport const BeforeDashboardClient = () => {\n const { config } = useConfig()\n\n const [message, setMessage] = useState('')\n\n useEffect(() => {\n const fetchMessage = async () => {\n const response = await fetch(`${config.serverURL}${config.routes.api}/my-plugin-endpoint`)\n const result = await response.json()\n setMessage(result.message)\n }\n\n void fetchMessage()\n }, [config.serverURL, config.routes.api])\n\n return (\n <div>\n <h1>Added by the plugin: Before Dashboard Client</h1>\n <div>\n Message from the endpoint:\n <div>{message || 'Loading...'}</div>\n </div>\n </div>\n )\n}\n"],"names":["useConfig","useEffect","useState","BeforeDashboardClient","config","message","setMessage","fetchMessage","response","fetch","serverURL","routes","api","result","json","div","h1"],"mappings":"AAAA;;AACA,SAASA,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAE3C,OAAO,MAAMC,wBAAwB;IACnC,MAAM,EAAEC,MAAM,EAAE,GAAGJ;IAEnB,MAAM,CAACK,SAASC,WAAW,GAAGJ,SAAS;IAEvCD,UAAU;QACR,MAAMM,eAAe;YACnB,MAAMC,WAAW,MAAMC,MAAM,GAAGL,OAAOM,SAAS,GAAGN,OAAOO,MAAM,CAACC,GAAG,CAAC,mBAAmB,CAAC;YACzF,MAAMC,SAAS,MAAML,SAASM,IAAI;YAClCR,WAAWO,OAAOR,OAAO;QAC3B;QAEA,KAAKE;IACP,GAAG;QAACH,OAAOM,SAAS;QAAEN,OAAOO,MAAM,CAACC,GAAG;KAAC;IAExC,qBACE,MAACG;;0BACC,KAACC;0BAAG;;0BACJ,MAACD;;oBAAI;kCAEH,KAACA;kCAAKV,WAAW;;;;;;AAIzB,EAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import styles from './BeforeDashboardServer.module.css';
|
|
3
|
-
export const BeforeDashboardServer = async (props)=>{
|
|
4
|
-
const { payload } = props;
|
|
5
|
-
const { docs } = await payload.find({
|
|
6
|
-
collection: 'plugin-collection'
|
|
7
|
-
});
|
|
8
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
9
|
-
className: styles.wrapper,
|
|
10
|
-
children: [
|
|
11
|
-
/*#__PURE__*/ _jsx("h1", {
|
|
12
|
-
children: "Added by the plugin: Before Dashboard Server"
|
|
13
|
-
}),
|
|
14
|
-
"Docs from Local API:",
|
|
15
|
-
docs.map((doc)=>/*#__PURE__*/ _jsx("div", {
|
|
16
|
-
children: doc.id
|
|
17
|
-
}, doc.id))
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=BeforeDashboardServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/BeforeDashboardServer.tsx"],"sourcesContent":["import type { ServerComponentProps } from 'payload'\n\nimport styles from './BeforeDashboardServer.module.css'\n\nexport const BeforeDashboardServer = async (props: ServerComponentProps) => {\n const { payload } = props\n\n const { docs } = await payload.find({ collection: 'plugin-collection' })\n\n return (\n <div className={styles.wrapper}>\n <h1>Added by the plugin: Before Dashboard Server</h1>\n Docs from Local API:\n {docs.map((doc) => (\n <div key={doc.id}>{doc.id}</div>\n ))}\n </div>\n )\n}\n"],"names":["styles","BeforeDashboardServer","props","payload","docs","find","collection","div","className","wrapper","h1","map","doc","id"],"mappings":";AAEA,OAAOA,YAAY,qCAAoC;AAEvD,OAAO,MAAMC,wBAAwB,OAAOC;IAC1C,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,IAAI,EAAE,GAAG,MAAMD,QAAQE,IAAI,CAAC;QAAEC,YAAY;IAAoB;IAEtE,qBACE,MAACC;QAAIC,WAAWR,OAAOS,OAAO;;0BAC5B,KAACC;0BAAG;;YAAiD;YAEpDN,KAAKO,GAAG,CAAC,CAACC,oBACT,KAACL;8BAAkBK,IAAIC,EAAE;mBAAfD,IAAIC,EAAE;;;AAIxB,EAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/customEndpointHandler.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nexport const customEndpointHandler: PayloadHandler = () => {\n return Response.json({ message: 'Hello from custom endpoint' })\n}\n"],"names":["customEndpointHandler","Response","json","message"],"mappings":"AAEA,OAAO,MAAMA,wBAAwC;IACnD,OAAOC,SAASC,IAAI,CAAC;QAAEC,SAAS;IAA6B;AAC/D,EAAC"}
|