@adland/data 0.3.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @adland/data
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - af12999: include verification methods for ad models
8
+
9
+ ## 0.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 7fdfaeb: add prebuild
14
+
15
+ ### Patch Changes
16
+
17
+ - 7fdfaeb: Add prepublishOnly script to ensure package is built before publishing. This fixes the issue where published versions of @adland/data were missing the dist folder.
18
+
3
19
  ## 0.3.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.cjs ADDED
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+
5
+ // src/schemas/index.ts
6
+ var linkAdDataSchema = zod.z.object({
7
+ url: zod.z.string().nonoptional("URL is required")
8
+ });
9
+ var castAdDataSchema = zod.z.object({
10
+ hash: zod.z.string().nonoptional("Hash is required")
11
+ });
12
+ var miniappAdDataSchema = zod.z.object({
13
+ url: zod.z.string().nonoptional("URL is required")
14
+ });
15
+ var linkAdSchema = zod.z.object({
16
+ type: zod.z.literal("link"),
17
+ data: linkAdDataSchema
18
+ });
19
+ var castAdSchema = zod.z.object({
20
+ type: zod.z.literal("cast"),
21
+ data: castAdDataSchema
22
+ });
23
+ var miniappAdSchema = zod.z.object({
24
+ type: zod.z.literal("miniapp"),
25
+ data: miniappAdDataSchema
26
+ });
27
+ var adDataSchema = zod.z.discriminatedUnion("type", [
28
+ linkAdSchema,
29
+ castAdSchema,
30
+ miniappAdSchema
31
+ ]);
32
+ var adSchemas = {
33
+ link: linkAdSchema,
34
+ cast: castAdSchema,
35
+ miniapp: miniappAdSchema
36
+ };
37
+ function getAdSchema(type) {
38
+ return adSchemas[type];
39
+ }
40
+ function getAllAdSchemas() {
41
+ return adSchemas;
42
+ }
43
+ function validateAdData(data) {
44
+ const result = adDataSchema.safeParse(data);
45
+ if (result.success) {
46
+ return { success: true, data: result.data };
47
+ }
48
+ return { success: false, error: result.error };
49
+ }
50
+
51
+ // src/types/models.ts
52
+ var DataModel = class {
53
+ schema;
54
+ constructor(schema) {
55
+ this.schema = schema;
56
+ }
57
+ /**
58
+ * Validate input against Zod schema
59
+ */
60
+ async validate(input) {
61
+ return this.schema.parseAsync(input);
62
+ }
63
+ /**
64
+ * Custom async checks (override in subclasses)
65
+ * Throw an error if verification fails
66
+ */
67
+ async verify(_data) {
68
+ }
69
+ /**
70
+ * Full pipeline: validate → verify
71
+ */
72
+ async prepare(input) {
73
+ const parsed = await this.validate(input);
74
+ try {
75
+ await this.verify(parsed);
76
+ } catch (error) {
77
+ if (error instanceof Error) {
78
+ throw new Error(error.message);
79
+ }
80
+ throw new Error(`Verification failed for ${this.schema.description}`);
81
+ }
82
+ return parsed;
83
+ }
84
+ /**
85
+ * Safe validation that returns result instead of throwing
86
+ */
87
+ async safeValidate(input) {
88
+ const result = await this.schema.safeParseAsync(input);
89
+ if (result.success) {
90
+ return { success: true, data: result.data };
91
+ }
92
+ return { success: false, error: result.error };
93
+ }
94
+ /**
95
+ * Safe prepare that returns result instead of throwing
96
+ */
97
+ async safePrepare(input) {
98
+ const validation = await this.safeValidate(input);
99
+ if (!validation.success) {
100
+ return validation;
101
+ }
102
+ try {
103
+ await this.verify(validation.data);
104
+ return { success: true, data: validation.data };
105
+ } catch (error) {
106
+ return {
107
+ success: false,
108
+ error: error instanceof Error ? error.message : "Verification failed"
109
+ };
110
+ }
111
+ }
112
+ };
113
+
114
+ // src/models/AdModel.ts
115
+ var AdModel = class extends DataModel {
116
+ };
117
+
118
+ // src/models/LinkAdModel.ts
119
+ var LinkAdModel = class extends AdModel {
120
+ type = "link";
121
+ constructor() {
122
+ super(linkAdSchema);
123
+ }
124
+ async verify(data) {
125
+ const errorMessage = "Invalid link";
126
+ if (!data.data.url.startsWith("http")) {
127
+ throw new Error(errorMessage);
128
+ }
129
+ }
130
+ };
131
+
132
+ // src/constants.ts
133
+ var adlandApiUrl = process.env.NODE_ENV === "development" ? "http://localhost:3069" : "https://api.adland.space";
134
+
135
+ // src/models/CastAdModel.ts
136
+ var CastAdModel = class extends AdModel {
137
+ type = "cast";
138
+ constructor() {
139
+ super(castAdSchema);
140
+ }
141
+ async verify({ data: { hash } }) {
142
+ if (!this.isValidFormat(hash)) {
143
+ throw new Error("Invalid cast hash: must be a valid farcaster cast hash");
144
+ }
145
+ const errorMessage = "Cast hash verification failed";
146
+ const res = await fetch(`${adlandApiUrl}/verify/cast`, {
147
+ method: "POST",
148
+ headers: {
149
+ "Content-Type": "application/json"
150
+ },
151
+ body: JSON.stringify({ hash })
152
+ }).then((res2) => res2.json()).catch((err) => {
153
+ throw new Error(errorMessage);
154
+ });
155
+ console.log("res", res);
156
+ if (!res.verified) {
157
+ throw new Error(errorMessage);
158
+ }
159
+ }
160
+ /**
161
+ * Example: 0x9610d4a81c793ed6b8f4c44497f9b5f86f052f46
162
+ * @param hash
163
+ * @returns
164
+ */
165
+ isValidFormat(hash) {
166
+ return /^0x[0-9a-fA-F]{40}$/.test(hash);
167
+ }
168
+ };
169
+
170
+ // src/models/MiniAppAdModel.ts
171
+ var MiniAppAdModel = class extends AdModel {
172
+ type = "miniapp";
173
+ constructor() {
174
+ super(miniappAdSchema);
175
+ }
176
+ async verify(data) {
177
+ const errorMessage = "Miniapp domain verification failed";
178
+ const res = await fetch(`${adlandApiUrl}/verify/miniapp`, {
179
+ method: "POST",
180
+ body: JSON.stringify({ domain: data.data.url.split("//")[1] })
181
+ }).then((res2) => res2.json()).catch((err) => {
182
+ throw new Error(errorMessage);
183
+ });
184
+ if (!res.verified) {
185
+ throw new Error(errorMessage);
186
+ }
187
+ }
188
+ };
189
+
190
+ // src/models/index.ts
191
+ var adModels = {
192
+ link: new LinkAdModel(),
193
+ cast: new CastAdModel(),
194
+ miniapp: new MiniAppAdModel()
195
+ };
196
+ function getAdModel(type) {
197
+ return adModels[type];
198
+ }
199
+
200
+ // src/types/index.ts
201
+ var adTypes = ["link", "cast", "miniapp"];
202
+
203
+ exports.AdModel = AdModel;
204
+ exports.CastAdModel = CastAdModel;
205
+ exports.DataModel = DataModel;
206
+ exports.LinkAdModel = LinkAdModel;
207
+ exports.MiniAppAdModel = MiniAppAdModel;
208
+ exports.adDataSchema = adDataSchema;
209
+ exports.adModels = adModels;
210
+ exports.adSchemas = adSchemas;
211
+ exports.adTypes = adTypes;
212
+ exports.castAdSchema = castAdSchema;
213
+ exports.getAdModel = getAdModel;
214
+ exports.getAdSchema = getAdSchema;
215
+ exports.getAllAdSchemas = getAllAdSchemas;
216
+ exports.linkAdSchema = linkAdSchema;
217
+ exports.miniappAdSchema = miniappAdSchema;
218
+ exports.validateAdData = validateAdData;
219
+ //# sourceMappingURL=index.cjs.map
220
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schemas/index.ts","../src/types/models.ts","../src/models/AdModel.ts","../src/models/LinkAdModel.ts","../src/constants.ts","../src/models/CastAdModel.ts","../src/models/MiniAppAdModel.ts","../src/models/index.ts","../src/types/index.ts"],"names":["z","res"],"mappings":";;;;;AAKA,IAAM,gBAAA,GAAmBA,MAAE,MAAA,CAAO;AAAA,EAChC,GAAA,EAAKA,KAAA,CAAE,MAAA,EAAO,CAAE,YAAY,iBAAiB;AAC/C,CAAC,CAAA;AAKD,IAAM,gBAAA,GAAmBA,MAAE,MAAA,CAAO;AAAA,EAChC,IAAA,EAAMA,KAAA,CAAE,MAAA,EAAO,CAAE,YAAY,kBAAkB;AACjD,CAAC,CAAA;AAKD,IAAM,mBAAA,GAAsBA,MAAE,MAAA,CAAO;AAAA,EACnC,GAAA,EAAKA,KAAA,CAAE,MAAA,EAAO,CAAE,YAAY,iBAAiB;AAC/C,CAAC,CAAA;AAKM,IAAM,YAAA,GAAeA,MAAE,MAAA,CAAO;AAAA,EACnC,IAAA,EAAMA,KAA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,KAAQA,IAAAA,CAAI,IAAA,EAAM,CAAA,CACxB,KAAA,CAAM,CAAC,GAAA,KAAQ;AACd,MAAA,MAAM,IAAI,MAAM,YAAY,CAAA;AAAA,IAC9B,CAAC,CAAA;AAEH,IAAA,IAAI,CAAC,IAAI,QAAA,EAAU;AACjB,MAAA,MAAM,IAAI,MAAM,YAAY,CAAA;AAAA,IAC9B;AAAA,EACF;AACF;;;ACvBO,IAAM,QAAA,GAAW;AAAA,EACtB,IAAA,EAAM,IAAI,WAAA,EAAY;AAAA,EACtB,IAAA,EAAM,IAAI,WAAA,EAAY;AAAA,EACtB,OAAA,EAAS,IAAI,cAAA;AACf;AAKO,SAAS,WACd,IAAA,EAOY;AACZ,EAAA,OAAO,SAAS,IAAI,CAAA;AACtB;;;AClBO,IAAM,OAAA,GAAU,CAAC,MAAA,EAAQ,MAAA,EAAQ,SAAS","file":"index.cjs","sourcesContent":["import { z } from \"zod\";\n\n/**\n * Link ad data schema - basic link\n */\nconst linkAdDataSchema = z.object({\n url: z.string().nonoptional(\"URL is required\"),\n});\n\n/**\n * Cast ad data schema - link to a Farcaster cast\n */\nconst castAdDataSchema = z.object({\n hash: z.string().nonoptional(\"Hash is required\"),\n});\n\n/**\n * MiniApp ad data schema - link to a Farcaster mini app\n */\nconst miniappAdDataSchema = z.object({\n url: z.string().nonoptional(\"URL is required\"),\n});\n\n/**\n * Link ad schema - basic link\n */\nexport const linkAdSchema = z.object({\n type: z.literal(\"link\"),\n data: linkAdDataSchema,\n});\n\n/**\n * Cast ad schema - link to a Farcaster cast\n */\nexport const castAdSchema = z.object({\n type: z.literal(\"cast\"),\n data: castAdDataSchema,\n});\n\n/**\n * MiniApp ad schema - link to a Farcaster mini app\n */\nexport const miniappAdSchema = z.object({\n type: z.literal(\"miniapp\"),\n data: miniappAdDataSchema,\n});\n\n/**\n * Union schema for all ad types\n */\nexport const adDataSchema = z.discriminatedUnion(\"type\", [\n linkAdSchema,\n castAdSchema,\n miniappAdSchema,\n]);\n\n/**\n * All ad schemas as an object\n */\nexport const adSchemas = {\n link: linkAdSchema,\n cast: castAdSchema,\n miniapp: miniappAdSchema,\n} as const;\n\n/**\n * Get schema for a specific ad type\n */\nexport function getAdSchema(type: keyof typeof adSchemas) {\n return adSchemas[type];\n}\n\n/**\n * Get all ad schemas\n */\nexport function getAllAdSchemas() {\n return adSchemas;\n}\n\n/**\n * Validate ad data\n */\nexport function validateAdData(data: unknown): {\n success: boolean;\n data?: z.infer<typeof adDataSchema>;\n error?: z.ZodError;\n} {\n const result = adDataSchema.safeParse(data);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return { success: false, error: result.error };\n}\n","import { z } from \"zod\";\n\n/**\n * Base class for data models with schema validation and verification\n */\nexport abstract class DataModel<S extends z.ZodTypeAny> {\n readonly schema: S;\n\n constructor(schema: S) {\n this.schema = schema;\n }\n\n /**\n * Validate input against Zod schema\n */\n async validate(input: unknown): Promise<z.infer<S>> {\n return this.schema.parseAsync(input);\n }\n\n /**\n * Custom async checks (override in subclasses)\n * Throw an error if verification fails\n */\n async verify(_data: z.infer<S>): Promise<void> {\n // default: no extra checks\n }\n\n /**\n * Full pipeline: validate → verify\n */\n async prepare(input: unknown): Promise<z.infer<S>> {\n const parsed = await this.validate(input);\n try {\n await this.verify(parsed);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(error.message);\n }\n throw new Error(`Verification failed for ${this.schema.description}`);\n }\n return parsed;\n }\n\n /**\n * Safe validation that returns result instead of throwing\n */\n async safeValidate(input: unknown): Promise<{\n success: boolean;\n data?: z.infer<S>;\n error?: z.ZodError;\n }> {\n const result = await this.schema.safeParseAsync(input);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return { success: false, error: result.error };\n }\n\n /**\n * Safe prepare that returns result instead of throwing\n */\n async safePrepare(input: unknown): Promise<{\n success: boolean;\n data?: z.infer<S>;\n error?: string | z.ZodError;\n }> {\n const validation = await this.safeValidate(input);\n if (!validation.success) {\n return validation;\n }\n\n try {\n await this.verify(validation.data!);\n return { success: true, data: validation.data };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : \"Verification failed\",\n };\n }\n }\n}\n","import { z } from \"zod\";\nimport { DataModel } from \"../types/models\";\nimport type { LinkAd, CastAd, MiniAppAd } from \"../types\";\n\n/**\n * Base ad model class\n */\nexport abstract class AdModel<\n T extends LinkAd | CastAd | MiniAppAd,\n> extends DataModel<z.ZodType<T, any, any>> {\n abstract readonly type: T[\"type\"];\n}\n","import { AdModel } from \"./AdModel\";\nimport { linkAdSchema } from \"../schemas\";\nimport type { LinkAd } from \"../types\";\n\n/**\n * Link Ad Model\n */\nexport class LinkAdModel extends AdModel<LinkAd> {\n readonly type = \"link\" as const;\n\n constructor() {\n super(linkAdSchema);\n }\n\n async verify(data: LinkAd): Promise<void> {\n const errorMessage = \"Invalid link\";\n if (!data.data.url.startsWith(\"http\")) {\n throw new Error(errorMessage);\n }\n }\n}\n","export const adlandApiUrl =\n process.env.NODE_ENV === \"development\"\n ? \"http://localhost:3069\"\n : \"https://api.adland.space\";\n","import { AdModel } from \"./AdModel\";\nimport { castAdSchema } from \"../schemas\";\nimport type { CastAd } from \"../types\";\nimport { adlandApiUrl } from \"../constants\";\n\n/**\n * Cast Ad Model\n */\nexport class CastAdModel extends AdModel<CastAd> {\n readonly type = \"cast\" as const;\n\n constructor() {\n super(castAdSchema);\n }\n\n async verify({ data: { hash } }: CastAd): Promise<void> {\n if (!this.isValidFormat(hash)) {\n throw new Error(\"Invalid cast hash: must be a valid farcaster cast hash\");\n }\n\n const errorMessage = \"Cast hash verification failed\";\n\n const res = (await fetch(`${adlandApiUrl}/verify/cast`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ hash }),\n })\n .then((res) => res.json())\n .catch((err) => {\n throw new Error(errorMessage);\n })) as { verified: boolean };\n\n console.log(\"res\", res);\n\n if (!res.verified) {\n throw new Error(errorMessage);\n }\n }\n\n /**\n * Example: 0x9610d4a81c793ed6b8f4c44497f9b5f86f052f46\n * @param hash\n * @returns\n */\n private isValidFormat(hash: string): boolean {\n return /^0x[0-9a-fA-F]{40}$/.test(hash);\n }\n}\n","import { AdModel } from \"./AdModel\";\nimport { miniappAdSchema } from \"../schemas\";\nimport type { MiniAppAd } from \"../types\";\nimport { adlandApiUrl } from \"../constants\";\n\n/**\n * MiniApp Ad Model\n */\nexport class MiniAppAdModel extends AdModel<MiniAppAd> {\n readonly type = \"miniapp\" as const;\n\n constructor() {\n super(miniappAdSchema);\n }\n\n async verify(data: MiniAppAd): Promise<void> {\n const errorMessage = \"Miniapp domain verification failed\";\n const res = (await fetch(`${adlandApiUrl}/verify/miniapp`, {\n method: \"POST\",\n body: JSON.stringify({ domain: data.data.url.split(\"//\")[1] }),\n })\n .then((res) => res.json())\n .catch((err) => {\n throw new Error(errorMessage);\n })) as { verified: boolean };\n\n if (!res.verified) {\n throw new Error(errorMessage);\n }\n }\n}\n","import { LinkAdModel } from \"./LinkAdModel\";\nimport { CastAdModel } from \"./CastAdModel\";\nimport { MiniAppAdModel } from \"./MiniAppAdModel\";\n\n/**\n * Registry of all ad models\n */\nexport const adModels = {\n link: new LinkAdModel(),\n cast: new CastAdModel(),\n miniapp: new MiniAppAdModel(),\n} as const;\n\n/**\n * Get ad model for a specific type\n */\nexport function getAdModel<T extends \"link\" | \"cast\" | \"miniapp\">(\n type: T,\n): T extends \"link\"\n ? LinkAdModel\n : T extends \"cast\"\n ? CastAdModel\n : T extends \"miniapp\"\n ? MiniAppAdModel\n : never {\n return adModels[type] as any;\n}\n\nexport { DataModel } from \"../types/models\";\nexport { AdModel } from \"./AdModel\";\nexport { LinkAdModel } from \"./LinkAdModel\";\nexport { CastAdModel } from \"./CastAdModel\";\nexport { MiniAppAdModel } from \"./MiniAppAdModel\";\n","import { z } from \"zod\";\nimport {\n linkAdSchema,\n castAdSchema,\n miniappAdSchema,\n adDataSchema,\n} from \"../schemas\";\n\nexport const adTypes = [\"link\", \"cast\", \"miniapp\"] as const;\n\n/**\n * Base ad type\n */\nexport type AdType = (typeof adTypes)[number];\n\n/**\n * Link ad type - basic link\n */\nexport type LinkAd = z.infer<typeof linkAdSchema>;\n\n/**\n * Cast ad type - link to a Farcaster cast\n */\nexport type CastAd = z.infer<typeof castAdSchema>;\n\n/**\n * MiniApp ad type - link to a Farcaster mini app\n */\nexport type MiniAppAd = z.infer<typeof miniappAdSchema>;\n\n/**\n * Union type of all ad types\n */\nexport type AdData = z.infer<typeof adDataSchema>;\n"]}
@@ -0,0 +1,235 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Link ad schema - basic link
5
+ */
6
+ declare const linkAdSchema: z.ZodObject<{
7
+ type: z.ZodLiteral<"link">;
8
+ data: z.ZodObject<{
9
+ url: z.ZodNonOptional<z.ZodString>;
10
+ }, z.core.$strip>;
11
+ }, z.core.$strip>;
12
+ /**
13
+ * Cast ad schema - link to a Farcaster cast
14
+ */
15
+ declare const castAdSchema: z.ZodObject<{
16
+ type: z.ZodLiteral<"cast">;
17
+ data: z.ZodObject<{
18
+ hash: z.ZodNonOptional<z.ZodString>;
19
+ }, z.core.$strip>;
20
+ }, z.core.$strip>;
21
+ /**
22
+ * MiniApp ad schema - link to a Farcaster mini app
23
+ */
24
+ declare const miniappAdSchema: z.ZodObject<{
25
+ type: z.ZodLiteral<"miniapp">;
26
+ data: z.ZodObject<{
27
+ url: z.ZodNonOptional<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ }, z.core.$strip>;
30
+ /**
31
+ * Union schema for all ad types
32
+ */
33
+ declare const adDataSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
34
+ type: z.ZodLiteral<"link">;
35
+ data: z.ZodObject<{
36
+ url: z.ZodNonOptional<z.ZodString>;
37
+ }, z.core.$strip>;
38
+ }, z.core.$strip>, z.ZodObject<{
39
+ type: z.ZodLiteral<"cast">;
40
+ data: z.ZodObject<{
41
+ hash: z.ZodNonOptional<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ }, z.core.$strip>, z.ZodObject<{
44
+ type: z.ZodLiteral<"miniapp">;
45
+ data: z.ZodObject<{
46
+ url: z.ZodNonOptional<z.ZodString>;
47
+ }, z.core.$strip>;
48
+ }, z.core.$strip>], "type">;
49
+ /**
50
+ * All ad schemas as an object
51
+ */
52
+ declare const adSchemas: {
53
+ readonly link: z.ZodObject<{
54
+ type: z.ZodLiteral<"link">;
55
+ data: z.ZodObject<{
56
+ url: z.ZodNonOptional<z.ZodString>;
57
+ }, z.core.$strip>;
58
+ }, z.core.$strip>;
59
+ readonly cast: z.ZodObject<{
60
+ type: z.ZodLiteral<"cast">;
61
+ data: z.ZodObject<{
62
+ hash: z.ZodNonOptional<z.ZodString>;
63
+ }, z.core.$strip>;
64
+ }, z.core.$strip>;
65
+ readonly miniapp: z.ZodObject<{
66
+ type: z.ZodLiteral<"miniapp">;
67
+ data: z.ZodObject<{
68
+ url: z.ZodNonOptional<z.ZodString>;
69
+ }, z.core.$strip>;
70
+ }, z.core.$strip>;
71
+ };
72
+ /**
73
+ * Get schema for a specific ad type
74
+ */
75
+ declare function getAdSchema(type: keyof typeof adSchemas): z.ZodObject<{
76
+ type: z.ZodLiteral<"link">;
77
+ data: z.ZodObject<{
78
+ url: z.ZodNonOptional<z.ZodString>;
79
+ }, z.core.$strip>;
80
+ }, z.core.$strip> | z.ZodObject<{
81
+ type: z.ZodLiteral<"cast">;
82
+ data: z.ZodObject<{
83
+ hash: z.ZodNonOptional<z.ZodString>;
84
+ }, z.core.$strip>;
85
+ }, z.core.$strip> | z.ZodObject<{
86
+ type: z.ZodLiteral<"miniapp">;
87
+ data: z.ZodObject<{
88
+ url: z.ZodNonOptional<z.ZodString>;
89
+ }, z.core.$strip>;
90
+ }, z.core.$strip>;
91
+ /**
92
+ * Get all ad schemas
93
+ */
94
+ declare function getAllAdSchemas(): {
95
+ readonly link: z.ZodObject<{
96
+ type: z.ZodLiteral<"link">;
97
+ data: z.ZodObject<{
98
+ url: z.ZodNonOptional<z.ZodString>;
99
+ }, z.core.$strip>;
100
+ }, z.core.$strip>;
101
+ readonly cast: z.ZodObject<{
102
+ type: z.ZodLiteral<"cast">;
103
+ data: z.ZodObject<{
104
+ hash: z.ZodNonOptional<z.ZodString>;
105
+ }, z.core.$strip>;
106
+ }, z.core.$strip>;
107
+ readonly miniapp: z.ZodObject<{
108
+ type: z.ZodLiteral<"miniapp">;
109
+ data: z.ZodObject<{
110
+ url: z.ZodNonOptional<z.ZodString>;
111
+ }, z.core.$strip>;
112
+ }, z.core.$strip>;
113
+ };
114
+ /**
115
+ * Validate ad data
116
+ */
117
+ declare function validateAdData(data: unknown): {
118
+ success: boolean;
119
+ data?: z.infer<typeof adDataSchema>;
120
+ error?: z.ZodError;
121
+ };
122
+
123
+ /**
124
+ * Base class for data models with schema validation and verification
125
+ */
126
+ declare abstract class DataModel<S extends z.ZodTypeAny> {
127
+ readonly schema: S;
128
+ constructor(schema: S);
129
+ /**
130
+ * Validate input against Zod schema
131
+ */
132
+ validate(input: unknown): Promise<z.infer<S>>;
133
+ /**
134
+ * Custom async checks (override in subclasses)
135
+ * Throw an error if verification fails
136
+ */
137
+ verify(_data: z.infer<S>): Promise<void>;
138
+ /**
139
+ * Full pipeline: validate → verify
140
+ */
141
+ prepare(input: unknown): Promise<z.infer<S>>;
142
+ /**
143
+ * Safe validation that returns result instead of throwing
144
+ */
145
+ safeValidate(input: unknown): Promise<{
146
+ success: boolean;
147
+ data?: z.infer<S>;
148
+ error?: z.ZodError;
149
+ }>;
150
+ /**
151
+ * Safe prepare that returns result instead of throwing
152
+ */
153
+ safePrepare(input: unknown): Promise<{
154
+ success: boolean;
155
+ data?: z.infer<S>;
156
+ error?: string | z.ZodError;
157
+ }>;
158
+ }
159
+
160
+ declare const adTypes: readonly ["link", "cast", "miniapp"];
161
+ /**
162
+ * Base ad type
163
+ */
164
+ type AdType = (typeof adTypes)[number];
165
+ /**
166
+ * Link ad type - basic link
167
+ */
168
+ type LinkAd = z.infer<typeof linkAdSchema>;
169
+ /**
170
+ * Cast ad type - link to a Farcaster cast
171
+ */
172
+ type CastAd = z.infer<typeof castAdSchema>;
173
+ /**
174
+ * MiniApp ad type - link to a Farcaster mini app
175
+ */
176
+ type MiniAppAd = z.infer<typeof miniappAdSchema>;
177
+ /**
178
+ * Union type of all ad types
179
+ */
180
+ type AdData = z.infer<typeof adDataSchema>;
181
+
182
+ /**
183
+ * Base ad model class
184
+ */
185
+ declare abstract class AdModel<T extends LinkAd | CastAd | MiniAppAd> extends DataModel<z.ZodType<T, any, any>> {
186
+ abstract readonly type: T["type"];
187
+ }
188
+
189
+ /**
190
+ * Link Ad Model
191
+ */
192
+ declare class LinkAdModel extends AdModel<LinkAd> {
193
+ readonly type: "link";
194
+ constructor();
195
+ verify(data: LinkAd): Promise<void>;
196
+ }
197
+
198
+ /**
199
+ * Cast Ad Model
200
+ */
201
+ declare class CastAdModel extends AdModel<CastAd> {
202
+ readonly type: "cast";
203
+ constructor();
204
+ verify({ data: { hash } }: CastAd): Promise<void>;
205
+ /**
206
+ * Example: 0x9610d4a81c793ed6b8f4c44497f9b5f86f052f46
207
+ * @param hash
208
+ * @returns
209
+ */
210
+ private isValidFormat;
211
+ }
212
+
213
+ /**
214
+ * MiniApp Ad Model
215
+ */
216
+ declare class MiniAppAdModel extends AdModel<MiniAppAd> {
217
+ readonly type: "miniapp";
218
+ constructor();
219
+ verify(data: MiniAppAd): Promise<void>;
220
+ }
221
+
222
+ /**
223
+ * Registry of all ad models
224
+ */
225
+ declare const adModels: {
226
+ readonly link: LinkAdModel;
227
+ readonly cast: CastAdModel;
228
+ readonly miniapp: MiniAppAdModel;
229
+ };
230
+ /**
231
+ * Get ad model for a specific type
232
+ */
233
+ declare function getAdModel<T extends "link" | "cast" | "miniapp">(type: T): T extends "link" ? LinkAdModel : T extends "cast" ? CastAdModel : T extends "miniapp" ? MiniAppAdModel : never;
234
+
235
+ export { type AdData, AdModel, type AdType, type CastAd, CastAdModel, DataModel, type LinkAd, LinkAdModel, type MiniAppAd, MiniAppAdModel, adDataSchema, adModels, adSchemas, adTypes, castAdSchema, getAdModel, getAdSchema, getAllAdSchemas, linkAdSchema, miniappAdSchema, validateAdData };
@@ -0,0 +1,235 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Link ad schema - basic link
5
+ */
6
+ declare const linkAdSchema: z.ZodObject<{
7
+ type: z.ZodLiteral<"link">;
8
+ data: z.ZodObject<{
9
+ url: z.ZodNonOptional<z.ZodString>;
10
+ }, z.core.$strip>;
11
+ }, z.core.$strip>;
12
+ /**
13
+ * Cast ad schema - link to a Farcaster cast
14
+ */
15
+ declare const castAdSchema: z.ZodObject<{
16
+ type: z.ZodLiteral<"cast">;
17
+ data: z.ZodObject<{
18
+ hash: z.ZodNonOptional<z.ZodString>;
19
+ }, z.core.$strip>;
20
+ }, z.core.$strip>;
21
+ /**
22
+ * MiniApp ad schema - link to a Farcaster mini app
23
+ */
24
+ declare const miniappAdSchema: z.ZodObject<{
25
+ type: z.ZodLiteral<"miniapp">;
26
+ data: z.ZodObject<{
27
+ url: z.ZodNonOptional<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ }, z.core.$strip>;
30
+ /**
31
+ * Union schema for all ad types
32
+ */
33
+ declare const adDataSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
34
+ type: z.ZodLiteral<"link">;
35
+ data: z.ZodObject<{
36
+ url: z.ZodNonOptional<z.ZodString>;
37
+ }, z.core.$strip>;
38
+ }, z.core.$strip>, z.ZodObject<{
39
+ type: z.ZodLiteral<"cast">;
40
+ data: z.ZodObject<{
41
+ hash: z.ZodNonOptional<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ }, z.core.$strip>, z.ZodObject<{
44
+ type: z.ZodLiteral<"miniapp">;
45
+ data: z.ZodObject<{
46
+ url: z.ZodNonOptional<z.ZodString>;
47
+ }, z.core.$strip>;
48
+ }, z.core.$strip>], "type">;
49
+ /**
50
+ * All ad schemas as an object
51
+ */
52
+ declare const adSchemas: {
53
+ readonly link: z.ZodObject<{
54
+ type: z.ZodLiteral<"link">;
55
+ data: z.ZodObject<{
56
+ url: z.ZodNonOptional<z.ZodString>;
57
+ }, z.core.$strip>;
58
+ }, z.core.$strip>;
59
+ readonly cast: z.ZodObject<{
60
+ type: z.ZodLiteral<"cast">;
61
+ data: z.ZodObject<{
62
+ hash: z.ZodNonOptional<z.ZodString>;
63
+ }, z.core.$strip>;
64
+ }, z.core.$strip>;
65
+ readonly miniapp: z.ZodObject<{
66
+ type: z.ZodLiteral<"miniapp">;
67
+ data: z.ZodObject<{
68
+ url: z.ZodNonOptional<z.ZodString>;
69
+ }, z.core.$strip>;
70
+ }, z.core.$strip>;
71
+ };
72
+ /**
73
+ * Get schema for a specific ad type
74
+ */
75
+ declare function getAdSchema(type: keyof typeof adSchemas): z.ZodObject<{
76
+ type: z.ZodLiteral<"link">;
77
+ data: z.ZodObject<{
78
+ url: z.ZodNonOptional<z.ZodString>;
79
+ }, z.core.$strip>;
80
+ }, z.core.$strip> | z.ZodObject<{
81
+ type: z.ZodLiteral<"cast">;
82
+ data: z.ZodObject<{
83
+ hash: z.ZodNonOptional<z.ZodString>;
84
+ }, z.core.$strip>;
85
+ }, z.core.$strip> | z.ZodObject<{
86
+ type: z.ZodLiteral<"miniapp">;
87
+ data: z.ZodObject<{
88
+ url: z.ZodNonOptional<z.ZodString>;
89
+ }, z.core.$strip>;
90
+ }, z.core.$strip>;
91
+ /**
92
+ * Get all ad schemas
93
+ */
94
+ declare function getAllAdSchemas(): {
95
+ readonly link: z.ZodObject<{
96
+ type: z.ZodLiteral<"link">;
97
+ data: z.ZodObject<{
98
+ url: z.ZodNonOptional<z.ZodString>;
99
+ }, z.core.$strip>;
100
+ }, z.core.$strip>;
101
+ readonly cast: z.ZodObject<{
102
+ type: z.ZodLiteral<"cast">;
103
+ data: z.ZodObject<{
104
+ hash: z.ZodNonOptional<z.ZodString>;
105
+ }, z.core.$strip>;
106
+ }, z.core.$strip>;
107
+ readonly miniapp: z.ZodObject<{
108
+ type: z.ZodLiteral<"miniapp">;
109
+ data: z.ZodObject<{
110
+ url: z.ZodNonOptional<z.ZodString>;
111
+ }, z.core.$strip>;
112
+ }, z.core.$strip>;
113
+ };
114
+ /**
115
+ * Validate ad data
116
+ */
117
+ declare function validateAdData(data: unknown): {
118
+ success: boolean;
119
+ data?: z.infer<typeof adDataSchema>;
120
+ error?: z.ZodError;
121
+ };
122
+
123
+ /**
124
+ * Base class for data models with schema validation and verification
125
+ */
126
+ declare abstract class DataModel<S extends z.ZodTypeAny> {
127
+ readonly schema: S;
128
+ constructor(schema: S);
129
+ /**
130
+ * Validate input against Zod schema
131
+ */
132
+ validate(input: unknown): Promise<z.infer<S>>;
133
+ /**
134
+ * Custom async checks (override in subclasses)
135
+ * Throw an error if verification fails
136
+ */
137
+ verify(_data: z.infer<S>): Promise<void>;
138
+ /**
139
+ * Full pipeline: validate → verify
140
+ */
141
+ prepare(input: unknown): Promise<z.infer<S>>;
142
+ /**
143
+ * Safe validation that returns result instead of throwing
144
+ */
145
+ safeValidate(input: unknown): Promise<{
146
+ success: boolean;
147
+ data?: z.infer<S>;
148
+ error?: z.ZodError;
149
+ }>;
150
+ /**
151
+ * Safe prepare that returns result instead of throwing
152
+ */
153
+ safePrepare(input: unknown): Promise<{
154
+ success: boolean;
155
+ data?: z.infer<S>;
156
+ error?: string | z.ZodError;
157
+ }>;
158
+ }
159
+
160
+ declare const adTypes: readonly ["link", "cast", "miniapp"];
161
+ /**
162
+ * Base ad type
163
+ */
164
+ type AdType = (typeof adTypes)[number];
165
+ /**
166
+ * Link ad type - basic link
167
+ */
168
+ type LinkAd = z.infer<typeof linkAdSchema>;
169
+ /**
170
+ * Cast ad type - link to a Farcaster cast
171
+ */
172
+ type CastAd = z.infer<typeof castAdSchema>;
173
+ /**
174
+ * MiniApp ad type - link to a Farcaster mini app
175
+ */
176
+ type MiniAppAd = z.infer<typeof miniappAdSchema>;
177
+ /**
178
+ * Union type of all ad types
179
+ */
180
+ type AdData = z.infer<typeof adDataSchema>;
181
+
182
+ /**
183
+ * Base ad model class
184
+ */
185
+ declare abstract class AdModel<T extends LinkAd | CastAd | MiniAppAd> extends DataModel<z.ZodType<T, any, any>> {
186
+ abstract readonly type: T["type"];
187
+ }
188
+
189
+ /**
190
+ * Link Ad Model
191
+ */
192
+ declare class LinkAdModel extends AdModel<LinkAd> {
193
+ readonly type: "link";
194
+ constructor();
195
+ verify(data: LinkAd): Promise<void>;
196
+ }
197
+
198
+ /**
199
+ * Cast Ad Model
200
+ */
201
+ declare class CastAdModel extends AdModel<CastAd> {
202
+ readonly type: "cast";
203
+ constructor();
204
+ verify({ data: { hash } }: CastAd): Promise<void>;
205
+ /**
206
+ * Example: 0x9610d4a81c793ed6b8f4c44497f9b5f86f052f46
207
+ * @param hash
208
+ * @returns
209
+ */
210
+ private isValidFormat;
211
+ }
212
+
213
+ /**
214
+ * MiniApp Ad Model
215
+ */
216
+ declare class MiniAppAdModel extends AdModel<MiniAppAd> {
217
+ readonly type: "miniapp";
218
+ constructor();
219
+ verify(data: MiniAppAd): Promise<void>;
220
+ }
221
+
222
+ /**
223
+ * Registry of all ad models
224
+ */
225
+ declare const adModels: {
226
+ readonly link: LinkAdModel;
227
+ readonly cast: CastAdModel;
228
+ readonly miniapp: MiniAppAdModel;
229
+ };
230
+ /**
231
+ * Get ad model for a specific type
232
+ */
233
+ declare function getAdModel<T extends "link" | "cast" | "miniapp">(type: T): T extends "link" ? LinkAdModel : T extends "cast" ? CastAdModel : T extends "miniapp" ? MiniAppAdModel : never;
234
+
235
+ export { type AdData, AdModel, type AdType, type CastAd, CastAdModel, DataModel, type LinkAd, LinkAdModel, type MiniAppAd, MiniAppAdModel, adDataSchema, adModels, adSchemas, adTypes, castAdSchema, getAdModel, getAdSchema, getAllAdSchemas, linkAdSchema, miniappAdSchema, validateAdData };
package/dist/index.js ADDED
@@ -0,0 +1,203 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/schemas/index.ts
4
+ var linkAdDataSchema = z.object({
5
+ url: z.string().nonoptional("URL is required")
6
+ });
7
+ var castAdDataSchema = z.object({
8
+ hash: z.string().nonoptional("Hash is required")
9
+ });
10
+ var miniappAdDataSchema = z.object({
11
+ url: z.string().nonoptional("URL is required")
12
+ });
13
+ var linkAdSchema = z.object({
14
+ type: z.literal("link"),
15
+ data: linkAdDataSchema
16
+ });
17
+ var castAdSchema = z.object({
18
+ type: z.literal("cast"),
19
+ data: castAdDataSchema
20
+ });
21
+ var miniappAdSchema = z.object({
22
+ type: z.literal("miniapp"),
23
+ data: miniappAdDataSchema
24
+ });
25
+ var adDataSchema = z.discriminatedUnion("type", [
26
+ linkAdSchema,
27
+ castAdSchema,
28
+ miniappAdSchema
29
+ ]);
30
+ var adSchemas = {
31
+ link: linkAdSchema,
32
+ cast: castAdSchema,
33
+ miniapp: miniappAdSchema
34
+ };
35
+ function getAdSchema(type) {
36
+ return adSchemas[type];
37
+ }
38
+ function getAllAdSchemas() {
39
+ return adSchemas;
40
+ }
41
+ function validateAdData(data) {
42
+ const result = adDataSchema.safeParse(data);
43
+ if (result.success) {
44
+ return { success: true, data: result.data };
45
+ }
46
+ return { success: false, error: result.error };
47
+ }
48
+
49
+ // src/types/models.ts
50
+ var DataModel = class {
51
+ schema;
52
+ constructor(schema) {
53
+ this.schema = schema;
54
+ }
55
+ /**
56
+ * Validate input against Zod schema
57
+ */
58
+ async validate(input) {
59
+ return this.schema.parseAsync(input);
60
+ }
61
+ /**
62
+ * Custom async checks (override in subclasses)
63
+ * Throw an error if verification fails
64
+ */
65
+ async verify(_data) {
66
+ }
67
+ /**
68
+ * Full pipeline: validate → verify
69
+ */
70
+ async prepare(input) {
71
+ const parsed = await this.validate(input);
72
+ try {
73
+ await this.verify(parsed);
74
+ } catch (error) {
75
+ if (error instanceof Error) {
76
+ throw new Error(error.message);
77
+ }
78
+ throw new Error(`Verification failed for ${this.schema.description}`);
79
+ }
80
+ return parsed;
81
+ }
82
+ /**
83
+ * Safe validation that returns result instead of throwing
84
+ */
85
+ async safeValidate(input) {
86
+ const result = await this.schema.safeParseAsync(input);
87
+ if (result.success) {
88
+ return { success: true, data: result.data };
89
+ }
90
+ return { success: false, error: result.error };
91
+ }
92
+ /**
93
+ * Safe prepare that returns result instead of throwing
94
+ */
95
+ async safePrepare(input) {
96
+ const validation = await this.safeValidate(input);
97
+ if (!validation.success) {
98
+ return validation;
99
+ }
100
+ try {
101
+ await this.verify(validation.data);
102
+ return { success: true, data: validation.data };
103
+ } catch (error) {
104
+ return {
105
+ success: false,
106
+ error: error instanceof Error ? error.message : "Verification failed"
107
+ };
108
+ }
109
+ }
110
+ };
111
+
112
+ // src/models/AdModel.ts
113
+ var AdModel = class extends DataModel {
114
+ };
115
+
116
+ // src/models/LinkAdModel.ts
117
+ var LinkAdModel = class extends AdModel {
118
+ type = "link";
119
+ constructor() {
120
+ super(linkAdSchema);
121
+ }
122
+ async verify(data) {
123
+ const errorMessage = "Invalid link";
124
+ if (!data.data.url.startsWith("http")) {
125
+ throw new Error(errorMessage);
126
+ }
127
+ }
128
+ };
129
+
130
+ // src/constants.ts
131
+ var adlandApiUrl = process.env.NODE_ENV === "development" ? "http://localhost:3069" : "https://api.adland.space";
132
+
133
+ // src/models/CastAdModel.ts
134
+ var CastAdModel = class extends AdModel {
135
+ type = "cast";
136
+ constructor() {
137
+ super(castAdSchema);
138
+ }
139
+ async verify({ data: { hash } }) {
140
+ if (!this.isValidFormat(hash)) {
141
+ throw new Error("Invalid cast hash: must be a valid farcaster cast hash");
142
+ }
143
+ const errorMessage = "Cast hash verification failed";
144
+ const res = await fetch(`${adlandApiUrl}/verify/cast`, {
145
+ method: "POST",
146
+ headers: {
147
+ "Content-Type": "application/json"
148
+ },
149
+ body: JSON.stringify({ hash })
150
+ }).then((res2) => res2.json()).catch((err) => {
151
+ throw new Error(errorMessage);
152
+ });
153
+ console.log("res", res);
154
+ if (!res.verified) {
155
+ throw new Error(errorMessage);
156
+ }
157
+ }
158
+ /**
159
+ * Example: 0x9610d4a81c793ed6b8f4c44497f9b5f86f052f46
160
+ * @param hash
161
+ * @returns
162
+ */
163
+ isValidFormat(hash) {
164
+ return /^0x[0-9a-fA-F]{40}$/.test(hash);
165
+ }
166
+ };
167
+
168
+ // src/models/MiniAppAdModel.ts
169
+ var MiniAppAdModel = class extends AdModel {
170
+ type = "miniapp";
171
+ constructor() {
172
+ super(miniappAdSchema);
173
+ }
174
+ async verify(data) {
175
+ const errorMessage = "Miniapp domain verification failed";
176
+ const res = await fetch(`${adlandApiUrl}/verify/miniapp`, {
177
+ method: "POST",
178
+ body: JSON.stringify({ domain: data.data.url.split("//")[1] })
179
+ }).then((res2) => res2.json()).catch((err) => {
180
+ throw new Error(errorMessage);
181
+ });
182
+ if (!res.verified) {
183
+ throw new Error(errorMessage);
184
+ }
185
+ }
186
+ };
187
+
188
+ // src/models/index.ts
189
+ var adModels = {
190
+ link: new LinkAdModel(),
191
+ cast: new CastAdModel(),
192
+ miniapp: new MiniAppAdModel()
193
+ };
194
+ function getAdModel(type) {
195
+ return adModels[type];
196
+ }
197
+
198
+ // src/types/index.ts
199
+ var adTypes = ["link", "cast", "miniapp"];
200
+
201
+ export { AdModel, CastAdModel, DataModel, LinkAdModel, MiniAppAdModel, adDataSchema, adModels, adSchemas, adTypes, castAdSchema, getAdModel, getAdSchema, getAllAdSchemas, linkAdSchema, miniappAdSchema, validateAdData };
202
+ //# sourceMappingURL=index.js.map
203
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schemas/index.ts","../src/types/models.ts","../src/models/AdModel.ts","../src/models/LinkAdModel.ts","../src/constants.ts","../src/models/CastAdModel.ts","../src/models/MiniAppAdModel.ts","../src/models/index.ts","../src/types/index.ts"],"names":["res"],"mappings":";;;AAKA,IAAM,gBAAA,GAAmB,EAAE,MAAA,CAAO;AAAA,EAChC,GAAA,EAAK,CAAA,CAAE,MAAA,EAAO,CAAE,YAAY,iBAAiB;AAC/C,CAAC,CAAA;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AAe,oCAAA;AACrB,IAAA,MAAM,GAAA,GAAO,MAAM,KAAA,CAAM,CAAA,EAAG,YAAY,CAAA,eAAA,CAAA,EAAmB;AAAA,MACzD,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,EAAE,MAAA,EAAQ,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,KAAA,CAAM,IAAI,CAAA,CAAE,CAAC,GAAG;AAAA,KAC9D,CAAA,CACE,IAAA,CAAK,CAACA,IAAAA,KAAQA,IAAAA,CAAI,IAAA,EAAM,CAAA,CACxB,KAAA,CAAM,CAAC,GAAA,KAAQ;AACd,MAAA,MAAM,IAAI,MAAM,YAAY,CAAA;AAAA,IAC9B,CAAC,CAAA;AAEH,IAAA,IAAI,CAAC,IAAI,QAAA,EAAU;AACjB,MAAA,MAAM,IAAI,MAAM,YAAY,CAAA;AAAA,IAC9B;AAAA,EACF;AACF;;;ACvBO,IAAM,QAAA,GAAW;AAAA,EACtB,IAAA,EAAM,IAAI,WAAA,EAAY;AAAA,EACtB,IAAA,EAAM,IAAI,WAAA,EAAY;AAAA,EACtB,OAAA,EAAS,IAAI,cAAA;AACf;AAKO,SAAS,WACd,IAAA,EAOY;AACZ,EAAA,OAAO,SAAS,IAAI,CAAA;AACtB;;;AClBO,IAAM,OAAA,GAAU,CAAC,MAAA,EAAQ,MAAA,EAAQ,SAAS","file":"index.js","sourcesContent":["import { z } from \"zod\";\n\n/**\n * Link ad data schema - basic link\n */\nconst linkAdDataSchema = z.object({\n url: z.string().nonoptional(\"URL is required\"),\n});\n\n/**\n * Cast ad data schema - link to a Farcaster cast\n */\nconst castAdDataSchema = z.object({\n hash: z.string().nonoptional(\"Hash is required\"),\n});\n\n/**\n * MiniApp ad data schema - link to a Farcaster mini app\n */\nconst miniappAdDataSchema = z.object({\n url: z.string().nonoptional(\"URL is required\"),\n});\n\n/**\n * Link ad schema - basic link\n */\nexport const linkAdSchema = z.object({\n type: z.literal(\"link\"),\n data: linkAdDataSchema,\n});\n\n/**\n * Cast ad schema - link to a Farcaster cast\n */\nexport const castAdSchema = z.object({\n type: z.literal(\"cast\"),\n data: castAdDataSchema,\n});\n\n/**\n * MiniApp ad schema - link to a Farcaster mini app\n */\nexport const miniappAdSchema = z.object({\n type: z.literal(\"miniapp\"),\n data: miniappAdDataSchema,\n});\n\n/**\n * Union schema for all ad types\n */\nexport const adDataSchema = z.discriminatedUnion(\"type\", [\n linkAdSchema,\n castAdSchema,\n miniappAdSchema,\n]);\n\n/**\n * All ad schemas as an object\n */\nexport const adSchemas = {\n link: linkAdSchema,\n cast: castAdSchema,\n miniapp: miniappAdSchema,\n} as const;\n\n/**\n * Get schema for a specific ad type\n */\nexport function getAdSchema(type: keyof typeof adSchemas) {\n return adSchemas[type];\n}\n\n/**\n * Get all ad schemas\n */\nexport function getAllAdSchemas() {\n return adSchemas;\n}\n\n/**\n * Validate ad data\n */\nexport function validateAdData(data: unknown): {\n success: boolean;\n data?: z.infer<typeof adDataSchema>;\n error?: z.ZodError;\n} {\n const result = adDataSchema.safeParse(data);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return { success: false, error: result.error };\n}\n","import { z } from \"zod\";\n\n/**\n * Base class for data models with schema validation and verification\n */\nexport abstract class DataModel<S extends z.ZodTypeAny> {\n readonly schema: S;\n\n constructor(schema: S) {\n this.schema = schema;\n }\n\n /**\n * Validate input against Zod schema\n */\n async validate(input: unknown): Promise<z.infer<S>> {\n return this.schema.parseAsync(input);\n }\n\n /**\n * Custom async checks (override in subclasses)\n * Throw an error if verification fails\n */\n async verify(_data: z.infer<S>): Promise<void> {\n // default: no extra checks\n }\n\n /**\n * Full pipeline: validate → verify\n */\n async prepare(input: unknown): Promise<z.infer<S>> {\n const parsed = await this.validate(input);\n try {\n await this.verify(parsed);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(error.message);\n }\n throw new Error(`Verification failed for ${this.schema.description}`);\n }\n return parsed;\n }\n\n /**\n * Safe validation that returns result instead of throwing\n */\n async safeValidate(input: unknown): Promise<{\n success: boolean;\n data?: z.infer<S>;\n error?: z.ZodError;\n }> {\n const result = await this.schema.safeParseAsync(input);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return { success: false, error: result.error };\n }\n\n /**\n * Safe prepare that returns result instead of throwing\n */\n async safePrepare(input: unknown): Promise<{\n success: boolean;\n data?: z.infer<S>;\n error?: string | z.ZodError;\n }> {\n const validation = await this.safeValidate(input);\n if (!validation.success) {\n return validation;\n }\n\n try {\n await this.verify(validation.data!);\n return { success: true, data: validation.data };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : \"Verification failed\",\n };\n }\n }\n}\n","import { z } from \"zod\";\nimport { DataModel } from \"../types/models\";\nimport type { LinkAd, CastAd, MiniAppAd } from \"../types\";\n\n/**\n * Base ad model class\n */\nexport abstract class AdModel<\n T extends LinkAd | CastAd | MiniAppAd,\n> extends DataModel<z.ZodType<T, any, any>> {\n abstract readonly type: T[\"type\"];\n}\n","import { AdModel } from \"./AdModel\";\nimport { linkAdSchema } from \"../schemas\";\nimport type { LinkAd } from \"../types\";\n\n/**\n * Link Ad Model\n */\nexport class LinkAdModel extends AdModel<LinkAd> {\n readonly type = \"link\" as const;\n\n constructor() {\n super(linkAdSchema);\n }\n\n async verify(data: LinkAd): Promise<void> {\n const errorMessage = \"Invalid link\";\n if (!data.data.url.startsWith(\"http\")) {\n throw new Error(errorMessage);\n }\n }\n}\n","export const adlandApiUrl =\n process.env.NODE_ENV === \"development\"\n ? \"http://localhost:3069\"\n : \"https://api.adland.space\";\n","import { AdModel } from \"./AdModel\";\nimport { castAdSchema } from \"../schemas\";\nimport type { CastAd } from \"../types\";\nimport { adlandApiUrl } from \"../constants\";\n\n/**\n * Cast Ad Model\n */\nexport class CastAdModel extends AdModel<CastAd> {\n readonly type = \"cast\" as const;\n\n constructor() {\n super(castAdSchema);\n }\n\n async verify({ data: { hash } }: CastAd): Promise<void> {\n if (!this.isValidFormat(hash)) {\n throw new Error(\"Invalid cast hash: must be a valid farcaster cast hash\");\n }\n\n const errorMessage = \"Cast hash verification failed\";\n\n const res = (await fetch(`${adlandApiUrl}/verify/cast`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ hash }),\n })\n .then((res) => res.json())\n .catch((err) => {\n throw new Error(errorMessage);\n })) as { verified: boolean };\n\n console.log(\"res\", res);\n\n if (!res.verified) {\n throw new Error(errorMessage);\n }\n }\n\n /**\n * Example: 0x9610d4a81c793ed6b8f4c44497f9b5f86f052f46\n * @param hash\n * @returns\n */\n private isValidFormat(hash: string): boolean {\n return /^0x[0-9a-fA-F]{40}$/.test(hash);\n }\n}\n","import { AdModel } from \"./AdModel\";\nimport { miniappAdSchema } from \"../schemas\";\nimport type { MiniAppAd } from \"../types\";\nimport { adlandApiUrl } from \"../constants\";\n\n/**\n * MiniApp Ad Model\n */\nexport class MiniAppAdModel extends AdModel<MiniAppAd> {\n readonly type = \"miniapp\" as const;\n\n constructor() {\n super(miniappAdSchema);\n }\n\n async verify(data: MiniAppAd): Promise<void> {\n const errorMessage = \"Miniapp domain verification failed\";\n const res = (await fetch(`${adlandApiUrl}/verify/miniapp`, {\n method: \"POST\",\n body: JSON.stringify({ domain: data.data.url.split(\"//\")[1] }),\n })\n .then((res) => res.json())\n .catch((err) => {\n throw new Error(errorMessage);\n })) as { verified: boolean };\n\n if (!res.verified) {\n throw new Error(errorMessage);\n }\n }\n}\n","import { LinkAdModel } from \"./LinkAdModel\";\nimport { CastAdModel } from \"./CastAdModel\";\nimport { MiniAppAdModel } from \"./MiniAppAdModel\";\n\n/**\n * Registry of all ad models\n */\nexport const adModels = {\n link: new LinkAdModel(),\n cast: new CastAdModel(),\n miniapp: new MiniAppAdModel(),\n} as const;\n\n/**\n * Get ad model for a specific type\n */\nexport function getAdModel<T extends \"link\" | \"cast\" | \"miniapp\">(\n type: T,\n): T extends \"link\"\n ? LinkAdModel\n : T extends \"cast\"\n ? CastAdModel\n : T extends \"miniapp\"\n ? MiniAppAdModel\n : never {\n return adModels[type] as any;\n}\n\nexport { DataModel } from \"../types/models\";\nexport { AdModel } from \"./AdModel\";\nexport { LinkAdModel } from \"./LinkAdModel\";\nexport { CastAdModel } from \"./CastAdModel\";\nexport { MiniAppAdModel } from \"./MiniAppAdModel\";\n","import { z } from \"zod\";\nimport {\n linkAdSchema,\n castAdSchema,\n miniappAdSchema,\n adDataSchema,\n} from \"../schemas\";\n\nexport const adTypes = [\"link\", \"cast\", \"miniapp\"] as const;\n\n/**\n * Base ad type\n */\nexport type AdType = (typeof adTypes)[number];\n\n/**\n * Link ad type - basic link\n */\nexport type LinkAd = z.infer<typeof linkAdSchema>;\n\n/**\n * Cast ad type - link to a Farcaster cast\n */\nexport type CastAd = z.infer<typeof castAdSchema>;\n\n/**\n * MiniApp ad type - link to a Farcaster mini app\n */\nexport type MiniAppAd = z.infer<typeof miniappAdSchema>;\n\n/**\n * Union type of all ad types\n */\nexport type AdData = z.infer<typeof adDataSchema>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adland/data",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,8 +17,14 @@
17
17
  },
18
18
  "./package.json": "./package.json"
19
19
  },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "CHANGELOG.md"
24
+ ],
20
25
  "dependencies": {
21
- "zod": "^4.1.12"
26
+ "zod": "4.1.12",
27
+ "tsup": "^8.0.1"
22
28
  },
23
29
  "devDependencies": {
24
30
  "@types/node": "^20",
@@ -28,7 +34,6 @@
28
34
  "eslint": "^8",
29
35
  "eslint-config-turbo": "2.0.6",
30
36
  "eslint-plugin-only-warn": "^1.1.0",
31
- "tsup": "^8.0.1",
32
37
  "typescript": "^5.4.5"
33
38
  },
34
39
  "scripts": {
package/.eslintrc.js DELETED
@@ -1,34 +0,0 @@
1
- const { resolve } = require("node:path");
2
-
3
- const project = resolve(process.cwd(), "tsconfig.json");
4
-
5
- /** @type {import("eslint").Linter.Config} */
6
- module.exports = {
7
- extends: ["eslint:recommended", "turbo"],
8
- plugins: ["only-warn"],
9
- globals: {
10
- React: true,
11
- JSX: true,
12
- },
13
- env: {
14
- node: true,
15
- },
16
- settings: {
17
- "import/resolver": {
18
- typescript: {
19
- project,
20
- },
21
- },
22
- },
23
- ignorePatterns: [
24
- // Ignore dotfiles
25
- ".*.js",
26
- "node_modules/",
27
- "dist/",
28
- ],
29
- overrides: [
30
- {
31
- files: ["*.js?(x)", "*.ts?(x)"],
32
- },
33
- ],
34
- };
package/src/index.ts DELETED
@@ -1,22 +0,0 @@
1
- // Export types (derived from Zod schemas)
2
- export type {
3
- AdType,
4
- AdData,
5
- LinkAd,
6
- CastAd,
7
- MiniAppAd,
8
- TokenAd,
9
- } from "./types";
10
-
11
- // Export Zod schemas
12
- export {
13
- linkAdSchema,
14
- castAdSchema,
15
- miniappAdSchema,
16
- tokenAdSchema,
17
- adDataSchema,
18
- adSchemas,
19
- getAdSchema,
20
- getAllAdSchemas,
21
- validateAdData,
22
- } from "./schemas";
@@ -1,114 +0,0 @@
1
- import { z } from "zod";
2
-
3
- /**
4
- * Link ad data schema - basic link
5
- */
6
- const linkAdDataSchema = z.object({
7
- url: z.string().url("Must be a valid URL").nonoptional("URL is required"),
8
- });
9
-
10
- /**
11
- * Cast ad data schema - link to a Farcaster cast
12
- */
13
- const castAdDataSchema = z.object({
14
- url: z.string().url("Must be a valid URL").nonoptional("URL is required"),
15
- });
16
-
17
- /**
18
- * MiniApp ad data schema - link to a Farcaster mini app
19
- */
20
- const miniappAdDataSchema = z.object({
21
- url: z.string().url("Must be a valid URL").nonoptional("URL is required"),
22
- icon: z.string().url("Must be a valid URL").optional(),
23
- name: z.string().optional(),
24
- creatorPfpUrl: z.string().url("Must be a valid URL").optional(),
25
- creatorUsername: z.string().optional(),
26
- });
27
-
28
- /**
29
- * Token ad data schema - token information
30
- */
31
- const tokenAdDataSchema = z.object({
32
- token: z.string().min(1, "Token is required"),
33
- });
34
-
35
- /**
36
- * Link ad schema - basic link
37
- */
38
- export const linkAdSchema = z.object({
39
- type: z.literal("link"),
40
- data: linkAdDataSchema,
41
- });
42
-
43
- /**
44
- * Cast ad schema - link to a Farcaster cast
45
- */
46
- export const castAdSchema = z.object({
47
- type: z.literal("cast"),
48
- data: castAdDataSchema,
49
- });
50
-
51
- /**
52
- * MiniApp ad schema - link to a Farcaster mini app
53
- */
54
- export const miniappAdSchema = z.object({
55
- type: z.literal("miniapp"),
56
- data: miniappAdDataSchema,
57
- });
58
-
59
- /**
60
- * Token ad schema - token information
61
- */
62
- export const tokenAdSchema = z.object({
63
- type: z.literal("token"),
64
- data: tokenAdDataSchema,
65
- });
66
-
67
- /**
68
- * Union schema for all ad types
69
- */
70
- export const adDataSchema = z.discriminatedUnion("type", [
71
- linkAdSchema,
72
- castAdSchema,
73
- miniappAdSchema,
74
- tokenAdSchema,
75
- ]);
76
-
77
- /**
78
- * All ad schemas as an object
79
- */
80
- export const adSchemas = {
81
- link: linkAdSchema,
82
- cast: castAdSchema,
83
- miniapp: miniappAdSchema,
84
- token: tokenAdSchema,
85
- } as const;
86
-
87
- /**
88
- * Get schema for a specific ad type
89
- */
90
- export function getAdSchema(type: keyof typeof adSchemas) {
91
- return adSchemas[type];
92
- }
93
-
94
- /**
95
- * Get all ad schemas
96
- */
97
- export function getAllAdSchemas() {
98
- return adSchemas;
99
- }
100
-
101
- /**
102
- * Validate ad data
103
- */
104
- export function validateAdData(data: unknown): {
105
- success: boolean;
106
- data?: z.infer<typeof adDataSchema>;
107
- error?: z.ZodError;
108
- } {
109
- const result = adDataSchema.safeParse(data);
110
- if (result.success) {
111
- return { success: true, data: result.data };
112
- }
113
- return { success: false, error: result.error };
114
- }
@@ -1,38 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- linkAdSchema,
4
- castAdSchema,
5
- miniappAdSchema,
6
- tokenAdSchema,
7
- adDataSchema,
8
- } from "../schemas";
9
-
10
- /**
11
- * Base ad type
12
- */
13
- export type AdType = "link" | "cast" | "miniapp" | "token";
14
-
15
- /**
16
- * Link ad type - basic link
17
- */
18
- export type LinkAd = z.infer<typeof linkAdSchema>;
19
-
20
- /**
21
- * Cast ad type - link to a Farcaster cast
22
- */
23
- export type CastAd = z.infer<typeof castAdSchema>;
24
-
25
- /**
26
- * MiniApp ad type - link to a Farcaster mini app
27
- */
28
- export type MiniAppAd = z.infer<typeof miniappAdSchema>;
29
-
30
- /**
31
- * Token ad type - token information
32
- */
33
- export type TokenAd = z.infer<typeof tokenAdSchema>;
34
-
35
- /**
36
- * Union type of all ad types
37
- */
38
- export type AdData = z.infer<typeof adDataSchema>;
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "declarationMap": true,
6
- "esModuleInterop": true,
7
- "incremental": false,
8
- "isolatedModules": true,
9
- "lib": ["es2022"],
10
- "module": "ESNext",
11
- "moduleDetection": "force",
12
- "moduleResolution": "bundler",
13
- "noUncheckedIndexedAccess": true,
14
- "resolveJsonModule": true,
15
- "skipLibCheck": true,
16
- "strict": true,
17
- "target": "ES2022",
18
- "baseUrl": ".",
19
- "paths": {
20
- "@adland/data/*": ["./src/*"]
21
- },
22
- "outDir": "./dist"
23
- },
24
- "include": ["src"],
25
- "exclude": ["node_modules", "dist"]
26
- }
27
-
package/tsup.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- format: ["cjs", "esm"],
6
- dts: true,
7
- splitting: false,
8
- sourcemap: true,
9
- clean: true,
10
- treeshake: true,
11
- });
12
-