@sanity/form-toolkit 2.2.3 → 3.0.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/LICENSE +2 -1
- package/dist/_chunks-es/{create-handler.mjs → create-handler.js} +45 -17
- package/dist/_chunks-es/create-handler.js.map +1 -0
- package/dist/form-renderer/index.d.ts +53 -64
- package/dist/form-renderer/index.d.ts.map +1 -0
- package/dist/form-renderer/index.js +123 -108
- package/dist/form-renderer/index.js.map +1 -1
- package/dist/form-schema/index.d.ts +7 -11
- package/dist/form-schema/index.d.ts.map +1 -0
- package/dist/form-schema/index.js +181 -181
- package/dist/form-schema/index.js.map +1 -1
- package/dist/formium/index.d.ts +4 -7
- package/dist/formium/index.d.ts.map +1 -0
- package/dist/formium/index.js +35 -25
- package/dist/formium/index.js.map +1 -1
- package/dist/hubspot/index.d.ts +52 -48
- package/dist/hubspot/index.d.ts.map +1 -0
- package/dist/hubspot/index.js +52 -26
- package/dist/hubspot/index.js.map +1 -1
- package/dist/mailchimp/index.d.ts +56 -42
- package/dist/mailchimp/index.d.ts.map +1 -0
- package/dist/mailchimp/index.js +55 -37
- package/dist/mailchimp/index.js.map +1 -1
- package/package.json +36 -107
- package/dist/_chunks-cjs/create-handler.js +0 -68
- package/dist/_chunks-cjs/create-handler.js.map +0 -1
- package/dist/_chunks-es/create-handler.mjs.map +0 -1
- package/dist/form-renderer/index.d.mts +0 -66
- package/dist/form-renderer/index.mjs +0 -128
- package/dist/form-renderer/index.mjs.map +0 -1
- package/dist/form-schema/index.d.mts +0 -28
- package/dist/form-schema/index.mjs +0 -230
- package/dist/form-schema/index.mjs.map +0 -1
- package/dist/formium/index.d.mts +0 -20
- package/dist/formium/index.mjs +0 -30
- package/dist/formium/index.mjs.map +0 -1
- package/dist/hubspot/index.d.mts +0 -49
- package/dist/hubspot/index.mjs +0 -48
- package/dist/hubspot/index.mjs.map +0 -1
- package/dist/mailchimp/index.d.mts +0 -45
- package/dist/mailchimp/index.mjs +0 -49
- package/dist/mailchimp/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/form-renderer/components/default-field.tsx +0 -123
- package/src/form-renderer/components/form-renderer.tsx +0 -62
- package/src/form-renderer/components/types.ts +0 -51
- package/src/form-renderer/index.ts +0 -4
- package/src/form-schema/components/validation-type.tsx +0 -14
- package/src/form-schema/index.ts +0 -35
- package/src/form-schema/schema-types/form-field.ts +0 -224
- package/src/form-schema/schema-types/form.ts +0 -52
- package/src/form-schema/schema-types/index.ts +0 -9
- package/src/formium/index.ts +0 -52
- package/src/hubspot/components/option.tsx +0 -17
- package/src/hubspot/create-handler.ts +0 -6
- package/src/hubspot/fetch-hubspot-data.ts +0 -33
- package/src/hubspot/index.ts +0 -52
- package/src/index.ts +0 -19
- package/src/mailchimp/components/option.tsx +0 -30
- package/src/mailchimp/create-handler.ts +0 -39
- package/src/mailchimp/index.ts +0 -43
- package/src/shared/create-handler.ts +0 -109
- package/v2-incompatible.js +0 -11
package/dist/hubspot/index.d.ts
CHANGED
|
@@ -1,49 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
declare const hubSpotHandler: ({
|
|
2
|
+
token
|
|
3
|
+
}: {
|
|
4
|
+
token: string;
|
|
5
|
+
}) => ((req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>) | import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>> | {
|
|
6
|
+
GET: ({
|
|
7
|
+
request
|
|
8
|
+
}: {
|
|
9
|
+
request: Request;
|
|
10
|
+
}) => Promise<Response>;
|
|
11
|
+
loader?: undefined;
|
|
12
|
+
get?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
loader: ({
|
|
15
|
+
request
|
|
16
|
+
}: {
|
|
17
|
+
request: Request;
|
|
18
|
+
}) => Promise<Response>;
|
|
19
|
+
GET?: undefined;
|
|
20
|
+
get?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
get: ({
|
|
23
|
+
request
|
|
24
|
+
}: {
|
|
25
|
+
request: Request;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
body: string;
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': string;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
32
|
+
GET?: undefined;
|
|
33
|
+
loader?: undefined;
|
|
34
|
+
};
|
|
35
|
+
type HubSpotForm = {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
type MappedResult = HubSpotForm & {
|
|
41
|
+
value: string;
|
|
42
|
+
};
|
|
43
|
+
declare function fetchHubSpotData({
|
|
44
|
+
token
|
|
45
|
+
}: {
|
|
46
|
+
token: string;
|
|
47
|
+
}): Promise<MappedResult[] | null>;
|
|
48
|
+
interface HubSpotInputConfig {
|
|
49
|
+
url: string | URL;
|
|
13
50
|
}
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
| EventHandler<EventHandlerRequest, Promise<unknown>>
|
|
18
|
-
| {
|
|
19
|
-
GET: ({request}: {request: Request}) => Promise<Response>
|
|
20
|
-
loader?: undefined
|
|
21
|
-
get?: undefined
|
|
22
|
-
}
|
|
23
|
-
| {
|
|
24
|
-
loader: ({request}: {request: Request}) => Promise<Response>
|
|
25
|
-
GET?: undefined
|
|
26
|
-
get?: undefined
|
|
27
|
-
}
|
|
28
|
-
| {
|
|
29
|
-
get: ({request}: {request: Request}) => Promise<{
|
|
30
|
-
body: string
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': string
|
|
33
|
-
}
|
|
34
|
-
}>
|
|
35
|
-
GET?: undefined
|
|
36
|
-
loader?: undefined
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export declare const hubSpotInput: Plugin_2<HubSpotInputConfig>
|
|
40
|
-
|
|
41
|
-
declare interface HubSpotInputConfig {
|
|
42
|
-
url: string | URL
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
declare type MappedResult = HubSpotForm & {
|
|
46
|
-
value: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export {}
|
|
51
|
+
declare const hubSpotInput: import("sanity").Plugin<HubSpotInputConfig>;
|
|
52
|
+
export { fetchHubSpotData, hubSpotHandler, hubSpotInput };
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/hubspot/create-handler.ts","../../src/hubspot/fetch-hubspot-data.ts","../../src/hubspot/index.ts"],"mappings":"cAGa,cAAA;EAAkB;AAAA;EAAU,KAAA;AAAA,QAAc,GAAA,iBAAA,eAAA,EAAA,GAAA,iBAAA,cAAA,KAAA,OAAA,uBAAA,YAAA,cAAA,mBAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCHlD,WAAA;EACH,EAAA;EACA,IAAA;EAAA,CACC,GAAA;AAAA;AAAA,KAGE,YAAA,GAAe,WAAW;EAC7B,KAAK;AAAA;AAAA,iBAEe,gBAAA;EAAkB;AAAA;EAAS,KAAA;AAAA,IAAiB,OAAA,CAAQ,YAAA;AAAA,UCHhE,kBAAA;EACR,GAAA,WAAc,GAAG;AAAA;AAAA,cAuBN,YAAA,mBAAY,MAAA,CAAA,kBAAA"}
|
package/dist/hubspot/index.js
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { asyncList } from "@sanity/sanity-plugin-async-list";
|
|
2
|
+
import { definePlugin } from "sanity";
|
|
3
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { Card, Text } from "@sanity/ui";
|
|
6
|
+
import { createHandler } from "../_chunks-es/create-handler.js";
|
|
7
|
+
const Option = (option) => {
|
|
8
|
+
const $ = c(8);
|
|
9
|
+
let t0;
|
|
10
|
+
$[0] !== option.name ? (t0 = /* @__PURE__ */ jsx(Text, { size: 2, textOverflow: "ellipsis", children: option.name }), $[0] = option.name, $[1] = t0) : t0 = $[1];
|
|
11
|
+
let t1;
|
|
12
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
13
|
+
background: "inherit"
|
|
14
|
+
}, $[2] = t1) : t1 = $[2];
|
|
15
|
+
const t2 = `ID: ${option.value}`;
|
|
16
|
+
let t3;
|
|
17
|
+
$[3] !== t2 ? (t3 = /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: "inherit", style: t1, children: /* @__PURE__ */ jsx(Text, { size: 1, textOverflow: "ellipsis", children: t2 }) }), $[3] = t2, $[4] = t3) : t3 = $[4];
|
|
18
|
+
let t4;
|
|
19
|
+
return $[5] !== t0 || $[6] !== t3 ? (t4 = /* @__PURE__ */ jsxs(Card, { "data-as": "button", padding: 3, radius: 2, tone: "inherit", children: [
|
|
20
|
+
t0,
|
|
21
|
+
t3
|
|
22
|
+
] }), $[5] = t0, $[6] = t3, $[7] = t4) : t4 = $[7], t4;
|
|
23
|
+
};
|
|
24
|
+
async function fetchHubSpotData({
|
|
25
|
+
token
|
|
26
|
+
}) {
|
|
9
27
|
try {
|
|
10
28
|
const apiResponse = await fetch("https://api.hubapi.com/marketing/v3/forms/?limit=9999", {
|
|
11
29
|
headers: {
|
|
@@ -14,31 +32,39 @@ async function fetchHubSpotData({ token }) {
|
|
|
14
32
|
});
|
|
15
33
|
if (!apiResponse.ok)
|
|
16
34
|
return console.error(`Failed to fetch data: ${apiResponse.statusText}`), null;
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
|
|
35
|
+
const {
|
|
36
|
+
results
|
|
37
|
+
} = await apiResponse.json();
|
|
38
|
+
return results.map((result) => Object.assign(result, {
|
|
20
39
|
value: result.id
|
|
21
40
|
}));
|
|
22
41
|
} catch (e) {
|
|
23
42
|
return console.error(e), null;
|
|
24
43
|
}
|
|
25
44
|
}
|
|
26
|
-
const hubSpotHandler = ({
|
|
45
|
+
const hubSpotHandler = ({
|
|
46
|
+
token
|
|
47
|
+
}) => createHandler(() => fetchHubSpotData({
|
|
48
|
+
token
|
|
49
|
+
})), hubSpotInput = definePlugin((options) => ({
|
|
27
50
|
name: "sanity-plugin-form-toolkit_hubspot-input",
|
|
28
|
-
plugins: [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
plugins: [asyncList({
|
|
52
|
+
schemaType: "hubSpotForm",
|
|
53
|
+
loader: async () => await (await fetch(options.url)).json(),
|
|
54
|
+
autocompleteProps: {
|
|
55
|
+
renderOption: (option) => (
|
|
56
|
+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- HubSpot loader returns options with a name property
|
|
57
|
+
Option(option)
|
|
58
|
+
),
|
|
59
|
+
renderValue(value, option) {
|
|
60
|
+
return option?.name ?? value;
|
|
37
61
|
}
|
|
38
|
-
}
|
|
39
|
-
]
|
|
62
|
+
}
|
|
63
|
+
})]
|
|
40
64
|
}));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
export {
|
|
66
|
+
fetchHubSpotData,
|
|
67
|
+
hubSpotHandler,
|
|
68
|
+
hubSpotInput
|
|
69
|
+
};
|
|
44
70
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/hubspot/components/option.tsx","../../src/hubspot/fetch-hubspot-data.ts","../../src/hubspot/create-handler.ts","../../src/hubspot/index.ts"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport type {ReactElement} from 'react'\n\nexport const Option = (option: {value: string; name: string}): ReactElement => {\n return (\n <Card data-as=\"button\" padding={3} radius={2} tone=\"inherit\">\n <Text size={2} textOverflow=\"ellipsis\">\n {option.name}\n </Text>\n <Card paddingTop={2} tone=\"inherit\" style={{background: 'inherit'}}>\n <Text size={1} textOverflow=\"ellipsis\">\n {`ID: ${option.value}`}\n </Text>\n </Card>\n </Card>\n )\n}\n","type HubSpotForm = {\n id: string\n name: string\n [key: string]: unknown // Additional properties from the API response\n}\n\ntype MappedResult = HubSpotForm & {\n value: string\n}\nexport async function fetchHubSpotData({token}: {token: string}): Promise<MappedResult[] | null> {\n try {\n const apiResponse = await fetch('https://api.hubapi.com/marketing/v3/forms/?limit=9999', {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n })\n\n if (!apiResponse.ok) {\n console.error(`Failed to fetch data: ${apiResponse.statusText}`)\n return null\n }\n\n const {results}: {results: HubSpotForm[]} = await apiResponse.json()\n\n return results.map((result) => ({
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/hubspot/components/option.tsx","../../src/hubspot/fetch-hubspot-data.ts","../../src/hubspot/create-handler.ts","../../src/hubspot/index.ts"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport type {ReactElement} from 'react'\n\nexport const Option = (option: {value: string; name: string}): ReactElement => {\n return (\n <Card data-as=\"button\" padding={3} radius={2} tone=\"inherit\">\n <Text size={2} textOverflow=\"ellipsis\">\n {option.name}\n </Text>\n <Card paddingTop={2} tone=\"inherit\" style={{background: 'inherit'}}>\n <Text size={1} textOverflow=\"ellipsis\">\n {`ID: ${option.value}`}\n </Text>\n </Card>\n </Card>\n )\n}\n","type HubSpotForm = {\n id: string\n name: string\n [key: string]: unknown // Additional properties from the API response\n}\n\ntype MappedResult = HubSpotForm & {\n value: string\n}\nexport async function fetchHubSpotData({token}: {token: string}): Promise<MappedResult[] | null> {\n try {\n const apiResponse = await fetch('https://api.hubapi.com/marketing/v3/forms/?limit=9999', {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n })\n\n if (!apiResponse.ok) {\n console.error(`Failed to fetch data: ${apiResponse.statusText}`)\n return null\n }\n\n const {results}: {results: HubSpotForm[]} = await apiResponse.json()\n\n return results.map((result) => Object.assign(result, {value: result.id}))\n } catch (e: unknown) {\n console.error(e)\n return null // Explicitly return null on error\n }\n}\n","import createHandler from '../shared/create-handler'\nimport {fetchHubSpotData} from './fetch-hubspot-data'\n\nexport const hubSpotHandler = ({token}: {token: string}) => {\n return createHandler(() => fetchHubSpotData({token}))\n}\n","import {asyncList} from '@sanity/sanity-plugin-async-list'\nimport {definePlugin} from 'sanity'\n\nimport {Option} from './components/option'\nimport {hubSpotHandler} from './create-handler'\nimport {fetchHubSpotData} from './fetch-hubspot-data'\ninterface HubSpotInputConfig {\n url: string | URL\n}\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {hubSpotInput} from '@sanity/form-toolkit/hubspot'\n *\n * export default defineConfig({\n * // ...\n * plugins: [\n * hubSpotInput({\n * url: 'http://localhost:3000/api/hubspot'\n * })\n * ],\n * })\n * ```\n */\n\ntype ExtendedOption = {value: string; name: string}\nexport {fetchHubSpotData, hubSpotHandler}\nexport const hubSpotInput = definePlugin<HubSpotInputConfig>((options) => {\n return {\n name: 'sanity-plugin-form-toolkit_hubspot-input',\n plugins: [\n asyncList({\n schemaType: 'hubSpotForm',\n loader: async () => {\n const data = await fetch(options.url)\n const body = await data.json()\n return body\n },\n autocompleteProps: {\n renderOption: (option) =>\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- HubSpot loader returns options with a name property\n Option(option as ExtendedOption),\n renderValue(value, option) {\n // @ts-expect-error can't extend default type?\n return option?.name ?? value\n },\n },\n }),\n ],\n }\n})\n"],"names":["Option","option","$","_c","t0","name","t1","for","background","t2","value","t3","t4","fetchHubSpotData","token","apiResponse","fetch","headers","Authorization","ok","console","error","statusText","results","json","map","result","Object","assign","id","e","hubSpotHandler","createHandler","hubSpotInput","definePlugin","options","plugins","asyncList","schemaType","loader","url","autocompleteProps","renderOption","renderValue"],"mappings":";;;;;;AAGO,MAAMA,SAASC,CAAAA,WAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAAF,IAAA,CAAA,MAAAD,OAAAI,QAGhBD,yBAAC,MAAA,EAAW,MAAA,GAAgB,cAAA,YACzBH,UAAAA,OAAMI,MACT,GAAOH,EAAA,CAAA,IAAAD,OAAAI,MAAAH,OAAAE,MAAAA,KAAAF,EAAA,CAAA;AAAA,MAAAI;AAAAJ,IAAA,CAAA,6BAAAK,IAAA,2BAAA,KACoCD,KAAA;AAAA,IAAAE,YAAa;AAAA,EAAA,GAAUN,OAAAI,MAAAA,KAAAJ,EAAA,CAAA;AAE7D,QAAAO,KAAA,OAAOR,OAAMS,KAAM;AAAE,MAAAC;AAAAT,WAAAO,MAF1BE,yBAAC,MAAA,EAAiB,eAAQ,MAAA,WAAiB,OAAAL,IACzC,8BAAC,MAAA,EAAW,MAAA,GAAgB,cAAA,YACzBG,UAAAA,GAAAA,CACH,EAAA,CACF,GAAOP,OAAAO,IAAAP,OAAAS,MAAAA,KAAAT,EAAA,CAAA;AAAA,MAAAU;AAAA,SAAAV,EAAA,CAAA,MAAAE,MAAAF,SAAAS,MARTC,KAAA,qBAAC,MAAA,EAAa,WAAA,UAAkB,SAAA,GAAW,QAAA,GAAQ,MAAA,WACjDR,UAAAA;AAAAA,IAAAA;AAAAA,IAGAO;AAAAA,EAAAA,EAAAA,CAKF,GAAOT,OAAAE,IAAAF,OAAAS,IAAAT,OAAAU,MAAAA,KAAAV,EAAA,CAAA,GATPU;AASO;ACLX,eAAsBC,iBAAiB;AAAA,EAACC;AAAsB,GAAmC;AAC/F,MAAI;AACF,UAAMC,cAAc,MAAMC,MAAM,yDAAyD;AAAA,MACvFC,SAAS;AAAA,QACPC,eAAe,UAAUJ,KAAK;AAAA,MAAA;AAAA,IAChC,CACD;AAED,QAAI,CAACC,YAAYI;AACfC,aAAAA,QAAQC,MAAM,yBAAyBN,YAAYO,UAAU,EAAE,GACxD;AAGT,UAAM;AAAA,MAACC;AAAAA,IAAAA,IAAqC,MAAMR,YAAYS,KAAAA;AAE9D,WAAOD,QAAQE,IAAKC,CAAAA,WAAWC,OAAOC,OAAOF,QAAQ;AAAA,MAAChB,OAAOgB,OAAOG;AAAAA,IAAAA,CAAG,CAAC;AAAA,EAC1E,SAASC,GAAY;AACnBV,WAAAA,QAAQC,MAAMS,CAAC,GACR;AAAA,EACT;AACF;AC1BO,MAAMC,iBAAiBA,CAAC;AAAA,EAACjB;AAAsB,MAC7CkB,cAAc,MAAMnB,iBAAiB;AAAA,EAACC;AAAK,CAAC,CAAC,GC0BzCmB,eAAeC,aAAkCC,CAAAA,aACrD;AAAA,EACL9B,MAAM;AAAA,EACN+B,SAAS,CACPC,UAAU;AAAA,IACRC,YAAY;AAAA,IACZC,QAAQ,YAEO,OADA,MAAMvB,MAAMmB,QAAQK,GAAG,GACZhB,KAAAA;AAAAA,IAG1BiB,mBAAmB;AAAA,MACjBC,cAAezC,CAAAA;AAAAA;AAAAA,QAEbD,OAAOC,MAAwB;AAAA;AAAA,MACjC0C,YAAYjC,OAAOT,QAAQ;AAEzB,eAAOA,QAAQI,QAAQK;AAAAA,MACzB;AAAA,IAAA;AAAA,EACF,CACD,CAAC;AAEN,EACD;"}
|
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
import {EventHandlerRequest} from 'h3'
|
|
3
|
-
import {IncomingMessage} from 'http'
|
|
4
|
-
import {Plugin as Plugin_2} from 'sanity'
|
|
5
|
-
import {ServerResponse} from 'http'
|
|
6
|
-
|
|
7
|
-
export declare function fetchMailchimpData({
|
|
1
|
+
declare function fetchMailchimpData({
|
|
8
2
|
key,
|
|
9
|
-
server
|
|
3
|
+
server
|
|
10
4
|
}: {
|
|
11
|
-
key: string
|
|
12
|
-
server: string
|
|
13
|
-
}): Promise<unknown
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
5
|
+
key: string;
|
|
6
|
+
server: string;
|
|
7
|
+
}): Promise<unknown>;
|
|
8
|
+
declare const mailchimpHandler: (keys: {
|
|
9
|
+
key: string;
|
|
10
|
+
server: string;
|
|
11
|
+
}) => ((req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>) | import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>> | {
|
|
12
|
+
GET: ({
|
|
13
|
+
request
|
|
14
|
+
}: {
|
|
15
|
+
request: Request;
|
|
16
|
+
}) => Promise<Response>;
|
|
17
|
+
loader?: undefined;
|
|
18
|
+
get?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
loader: ({
|
|
21
|
+
request
|
|
22
|
+
}: {
|
|
23
|
+
request: Request;
|
|
24
|
+
}) => Promise<Response>;
|
|
25
|
+
GET?: undefined;
|
|
26
|
+
get?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
get: ({
|
|
29
|
+
request
|
|
30
|
+
}: {
|
|
31
|
+
request: Request;
|
|
32
|
+
}) => Promise<{
|
|
33
|
+
body: string;
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': string;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
GET?: undefined;
|
|
39
|
+
loader?: undefined;
|
|
40
|
+
};
|
|
41
|
+
interface MailchimpInputConfig {
|
|
42
|
+
url: string | URL;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Usage in `sanity.config.ts` (or .js)
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* import {defineConfig} from 'sanity'
|
|
49
|
+
* import {mailchimpInput} from '@sanity/form-toolkit/mailchimp'
|
|
50
|
+
*
|
|
51
|
+
* export default defineConfig({
|
|
52
|
+
* // ...
|
|
53
|
+
* plugins: [mailchimpInput()],
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare const mailchimpInput: import("sanity").Plugin<MailchimpInputConfig>;
|
|
58
|
+
export { fetchMailchimpData, mailchimpHandler, mailchimpInput };
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/mailchimp/create-handler.ts","../../src/mailchimp/index.ts"],"mappings":"iBAUsB,kBAAA;EACpB,GAAA;EACA;AAAA;EAEA,GAAA;EACA,MAAA;AAAA,IACE,OAAA;AAAA,cAyBS,gBAAA,GAAoB,IAAA;EAAO,GAAA;EAAa,MAAA;AAAA,QAAe,GAAA,iBAAA,eAAA,EAAA,GAAA,iBAAA,cAAA,KAAA,OAAA,uBAAA,YAAA,cAAA,mBAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCnC1D,oBAAA;EACR,GAAA,WAAc,GAAG;AAAA;;;;;;;;;;;;ADSR;AAyBX;cCjBa,cAAA,mBAAc,MAAA,CAAA,oBAAA"}
|
package/dist/mailchimp/index.js
CHANGED
|
@@ -1,48 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const Option = (option) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
] });
|
|
1
|
+
import { asyncList } from "@sanity/sanity-plugin-async-list";
|
|
2
|
+
import { definePlugin } from "sanity";
|
|
3
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { Card, Text } from "@sanity/ui";
|
|
6
|
+
import mailchimp from "@mailchimp/mailchimp_marketing";
|
|
7
|
+
import { createHandler } from "../_chunks-es/create-handler.js";
|
|
8
|
+
const Option = (option) => {
|
|
9
|
+
const $ = c(8), t0 = `${option.form.header.text ? `${option.form.header.text} - ` : ""}${option.value}`;
|
|
10
|
+
let t1;
|
|
11
|
+
$[0] !== t0 ? (t1 = /* @__PURE__ */ jsx(Text, { size: 2, textOverflow: "ellipsis", children: t0 }), $[0] = t0, $[1] = t1) : t1 = $[1];
|
|
12
|
+
let t2;
|
|
13
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = {
|
|
14
|
+
background: "inherit"
|
|
15
|
+
}, $[2] = t2) : t2 = $[2];
|
|
16
|
+
const t3 = `${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? "" : "s"}`;
|
|
17
|
+
let t4;
|
|
18
|
+
$[3] !== t3 ? (t4 = /* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: "inherit", style: t2, children: /* @__PURE__ */ jsx(Text, { size: 1, textOverflow: "ellipsis", children: t3 }) }), $[3] = t3, $[4] = t4) : t4 = $[4];
|
|
19
|
+
let t5;
|
|
20
|
+
return $[5] !== t1 || $[6] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Card, { "data-as": "button", padding: 3, radius: 2, tone: "inherit", children: [
|
|
21
|
+
t1,
|
|
22
|
+
t4
|
|
23
|
+
] }), $[5] = t1, $[6] = t4, $[7] = t5) : t5 = $[7], t5;
|
|
24
|
+
};
|
|
12
25
|
async function fetchMailchimpData({
|
|
13
26
|
key,
|
|
14
27
|
server
|
|
15
28
|
}) {
|
|
16
|
-
|
|
29
|
+
mailchimp.setConfig({
|
|
17
30
|
apiKey: key,
|
|
18
31
|
server
|
|
19
32
|
});
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
const response = await mailchimp.lists.getAllLists();
|
|
34
|
+
if (!("lists" in response))
|
|
35
|
+
throw new Error("Failed to fetch Mailchimp lists");
|
|
36
|
+
return (await Promise.all(response.lists.map(async (list) => {
|
|
37
|
+
const {
|
|
38
|
+
signup_forms: signupForms
|
|
39
|
+
} = (
|
|
40
|
+
// @ts-expect-error getListSignupForms is missing from the mailchimp typings
|
|
41
|
+
await mailchimp.lists.getListSignupForms(list.id)
|
|
42
|
+
);
|
|
43
|
+
return signupForms.map((form) => ({
|
|
44
|
+
list,
|
|
45
|
+
form,
|
|
46
|
+
value: form.signup_form_url
|
|
47
|
+
}));
|
|
48
|
+
}))).flat();
|
|
31
49
|
}
|
|
32
|
-
const mailchimpHandler = (keys) => createHandler
|
|
50
|
+
const mailchimpHandler = (keys) => createHandler(() => fetchMailchimpData(keys)), mailchimpInput = definePlugin((options) => ({
|
|
33
51
|
name: "sanity-plugin-form-toolkit_mailchimp-input",
|
|
34
|
-
plugins: [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
]
|
|
52
|
+
plugins: [asyncList({
|
|
53
|
+
schemaType: "mailchimpForm",
|
|
54
|
+
loader: async () => await (await fetch(options.url)).json(),
|
|
55
|
+
autocompleteProps: {
|
|
56
|
+
//@ts-expect-error incorrect typing on props?
|
|
57
|
+
renderOption: (option) => Option(option)
|
|
58
|
+
}
|
|
59
|
+
})]
|
|
44
60
|
}));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
export {
|
|
62
|
+
fetchMailchimpData,
|
|
63
|
+
mailchimpHandler,
|
|
64
|
+
mailchimpInput
|
|
65
|
+
};
|
|
48
66
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/mailchimp/components/option.tsx","../../src/mailchimp/create-handler.ts","../../src/mailchimp/index.ts"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport type {ReactElement} from 'react'\n\nexport const Option = (option: {\n value: string\n form: {\n header: {\n text?: string\n }\n }\n list: {\n name: string\n stats: {\n member_count: number\n }\n }\n}): ReactElement => {\n return (\n <Card data-as=\"button\" padding={3} radius={2} tone=\"inherit\">\n <Text size={2} textOverflow=\"ellipsis\">\n {`${option.form.header.text ? `${option.form.header.text} - ` : ``}${option.value}`}\n </Text>\n <Card paddingTop={2} tone=\"inherit\" style={{background: 'inherit'}}>\n <Text size={1} textOverflow=\"ellipsis\">\n {`${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? '' : 's'}`}\n </Text>\n </Card>\n </Card>\n )\n}\n","import mailchimp from '@mailchimp/mailchimp_marketing'\n\nimport createHandler from '../shared/create-handler'\n\n// Fetch from Mailchimp's API\nexport async function fetchMailchimpData({\n key,\n server,\n}: {\n key: string\n server: string\n}): Promise<unknown> {\n mailchimp.setConfig({\n apiKey: key,\n server: server,\n })\n const
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/mailchimp/components/option.tsx","../../src/mailchimp/create-handler.ts","../../src/mailchimp/index.ts"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport type {ReactElement} from 'react'\n\nexport const Option = (option: {\n value: string\n form: {\n header: {\n text?: string\n }\n }\n list: {\n name: string\n stats: {\n member_count: number\n }\n }\n}): ReactElement => {\n return (\n <Card data-as=\"button\" padding={3} radius={2} tone=\"inherit\">\n <Text size={2} textOverflow=\"ellipsis\">\n {`${option.form.header.text ? `${option.form.header.text} - ` : ``}${option.value}`}\n </Text>\n <Card paddingTop={2} tone=\"inherit\" style={{background: 'inherit'}}>\n <Text size={1} textOverflow=\"ellipsis\">\n {`${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? '' : 's'}`}\n </Text>\n </Card>\n </Card>\n )\n}\n","import mailchimp from '@mailchimp/mailchimp_marketing'\n\nimport createHandler from '../shared/create-handler'\n\ninterface MailchimpSignupForm {\n signup_form_url: string\n [key: string]: unknown\n}\n\n// Fetch from Mailchimp's API\nexport async function fetchMailchimpData({\n key,\n server,\n}: {\n key: string\n server: string\n}): Promise<unknown> {\n mailchimp.setConfig({\n apiKey: key,\n server: server,\n })\n const response = await mailchimp.lists.getAllLists()\n if (!('lists' in response)) {\n throw new Error('Failed to fetch Mailchimp lists')\n }\n const signupFormsPerList = await Promise.all(\n response.lists.map(async (list) => {\n const {signup_forms: signupForms}: {signup_forms: MailchimpSignupForm[]} =\n // @ts-expect-error getListSignupForms is missing from the mailchimp typings\n await mailchimp.lists.getListSignupForms(list.id)\n return signupForms.map((form) => ({\n list,\n form,\n value: form.signup_form_url,\n }))\n }),\n )\n return signupFormsPerList.flat()\n}\n\n// Create the Mailchimp handler for a specific key and server\nexport const mailchimpHandler = (keys: {key: string; server: string}) => {\n return createHandler(() => fetchMailchimpData(keys))\n}\n","import {asyncList} from '@sanity/sanity-plugin-async-list'\nimport {definePlugin} from 'sanity'\n\nimport {Option} from './components/option'\nimport {mailchimpHandler} from './create-handler'\nimport {fetchMailchimpData} from './create-handler'\ninterface MailchimpInputConfig {\n url: string | URL\n}\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {mailchimpInput} from '@sanity/form-toolkit/mailchimp'\n *\n * export default defineConfig({\n * // ...\n * plugins: [mailchimpInput()],\n * })\n * ```\n */\nexport {fetchMailchimpData, mailchimpHandler}\nexport const mailchimpInput = definePlugin<MailchimpInputConfig>((options) => {\n return {\n name: 'sanity-plugin-form-toolkit_mailchimp-input',\n plugins: [\n asyncList({\n schemaType: 'mailchimpForm',\n loader: async () => {\n const data = await fetch(options.url)\n const body = await data.json()\n return body\n },\n autocompleteProps: {\n //@ts-expect-error incorrect typing on props?\n renderOption: (option) => Option(option),\n },\n }),\n ],\n }\n})\n"],"names":["Option","option","$","_c","t0","form","header","text","value","t1","t2","for","background","t3","list","name","stats","member_count","t4","t5","fetchMailchimpData","key","server","mailchimp","setConfig","apiKey","response","lists","getAllLists","Error","Promise","all","map","signup_forms","signupForms","getListSignupForms","id","signup_form_url","flat","mailchimpHandler","keys","createHandler","mailchimpInput","definePlugin","options","plugins","asyncList","schemaType","loader","fetch","url","json","autocompleteProps","renderOption"],"mappings":";;;;;;;AAGO,MAAMA,SAASC,CAAAA,WAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAiBbC,KAAA,GAAGH,OAAMI,KAAKC,OAAOC,OAAlB,GAA6BN,OAAMI,KAAKC,OAAOC,IAAK,QAApD,EAA8D,GAAGN,OAAMO,KAAM;AAAE,MAAAC;AAAAP,WAAAE,MADrFK,yBAAC,MAAA,EAAW,SAAgB,cAAA,YACzBL,cACH,GAAOF,OAAAE,IAAAF,OAAAO,MAAAA,KAAAP,EAAA,CAAA;AAAA,MAAAQ;AAAAR,IAAA,CAAA,6BAAAS,IAAA,2BAAA,KACoCD,KAAA;AAAA,IAAAE,YAAa;AAAA,EAAA,GAAUV,OAAAQ,MAAAA,KAAAR,EAAA,CAAA;AAE7D,QAAAW,KAAA,GAAGZ,OAAMa,KAAKC,IAAK,MAAMd,OAAMa,KAAKE,MAAMC,YAAa,UAAUhB,OAAMa,KAAKE,MAAMC,gBAAiB,IAAlC,KAAA,GAA8C;AAAE,MAAAC;AAAAhB,WAAAW,MAFtHK,yBAAC,MAAA,EAAiB,eAAQ,MAAA,WAAiB,OAAAR,IACzC,8BAAC,MAAA,EAAW,MAAA,GAAgB,cAAA,YACzBG,UAAAA,GAAAA,CACH,EAAA,CACF,GAAOX,OAAAW,IAAAX,OAAAgB,MAAAA,KAAAhB,EAAA,CAAA;AAAA,MAAAiB;AAAA,SAAAjB,EAAA,CAAA,MAAAO,MAAAP,SAAAgB,MARTC,KAAA,qBAAC,MAAA,EAAa,WAAA,UAAkB,SAAA,GAAW,QAAA,GAAQ,MAAA,WACjDV,UAAAA;AAAAA,IAAAA;AAAAA,IAGAS;AAAAA,EAAAA,EAAAA,CAKF,GAAOhB,OAAAO,IAAAP,OAAAgB,IAAAhB,OAAAiB,MAAAA,KAAAjB,EAAA,CAAA,GATPiB;AASO;ACjBX,eAAsBC,mBAAmB;AAAA,EACvCC;AAAAA,EACAC;AAIF,GAAqB;AACnBC,YAAUC,UAAU;AAAA,IAClBC,QAAQJ;AAAAA,IACRC;AAAAA,EAAAA,CACD;AACD,QAAMI,WAAW,MAAMH,UAAUI,MAAMC,YAAAA;AACvC,MAAI,EAAE,WAAWF;AACf,UAAM,IAAIG,MAAM,iCAAiC;AAcnD,UAZ2B,MAAMC,QAAQC,IACvCL,SAASC,MAAMK,IAAI,OAAOlB,SAAS;AACjC,UAAM;AAAA,MAACmB,cAAcC;AAAAA,IAAAA;AAAAA;AAAAA,MAEnB,MAAMX,UAAUI,MAAMQ,mBAAmBrB,KAAKsB,EAAE;AAAA;AAClD,WAAOF,YAAYF,IAAK3B,CAAAA,UAAU;AAAA,MAChCS;AAAAA,MACAT;AAAAA,MACAG,OAAOH,KAAKgC;AAAAA,IAAAA,EACZ;AAAA,EACJ,CAAC,CACH,GAC0BC,KAAAA;AAC5B;AAGO,MAAMC,mBAAoBC,CAAAA,SACxBC,cAAc,MAAMrB,mBAAmBoB,IAAI,CAAC,GClBxCE,iBAAiBC,aAAoCC,CAAAA,aACzD;AAAA,EACL7B,MAAM;AAAA,EACN8B,SAAS,CACPC,UAAU;AAAA,IACRC,YAAY;AAAA,IACZC,QAAQ,YAEO,OADA,MAAMC,MAAML,QAAQM,GAAG,GACZC,KAAAA;AAAAA,IAG1BC,mBAAmB;AAAA;AAAA,MAEjBC,cAAepD,CAAAA,WAAWD,OAAOC,MAAM;AAAA,IAAA;AAAA,EACzC,CACD,CAAC;AAEN,EACD;"}
|