@adland/data 0.2.0 → 0.4.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.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7fdfaeb: add prebuild
8
+
9
+ ### Patch Changes
10
+
11
+ - 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.
12
+
13
+ ## 0.3.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 5cee97e: add different ad types
18
+
3
19
  ## 0.2.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.cjs ADDED
@@ -0,0 +1,171 @@
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
+ await this.verify(parsed);
75
+ return parsed;
76
+ }
77
+ /**
78
+ * Safe validation that returns result instead of throwing
79
+ */
80
+ async safeValidate(input) {
81
+ const result = await this.schema.safeParseAsync(input);
82
+ if (result.success) {
83
+ return { success: true, data: result.data };
84
+ }
85
+ return { success: false, error: result.error };
86
+ }
87
+ /**
88
+ * Safe prepare that returns result instead of throwing
89
+ */
90
+ async safePrepare(input) {
91
+ const validation = await this.safeValidate(input);
92
+ if (!validation.success) {
93
+ return validation;
94
+ }
95
+ try {
96
+ await this.verify(validation.data);
97
+ return { success: true, data: validation.data };
98
+ } catch (error) {
99
+ return {
100
+ success: false,
101
+ error: error instanceof Error ? error.message : "Verification failed"
102
+ };
103
+ }
104
+ }
105
+ };
106
+
107
+ // src/models/AdModel.ts
108
+ var AdModel = class extends DataModel {
109
+ };
110
+
111
+ // src/models/LinkAdModel.ts
112
+ var LinkAdModel = class extends AdModel {
113
+ type = "link";
114
+ constructor() {
115
+ super(linkAdSchema);
116
+ }
117
+ async verify(data) {
118
+ }
119
+ };
120
+
121
+ // src/models/CastAdModel.ts
122
+ var CastAdModel = class extends AdModel {
123
+ type = "cast";
124
+ constructor() {
125
+ super(castAdSchema);
126
+ }
127
+ async verify(data) {
128
+ }
129
+ };
130
+
131
+ // src/models/MiniAppAdModel.ts
132
+ var MiniAppAdModel = class extends AdModel {
133
+ type = "miniapp";
134
+ constructor() {
135
+ super(miniappAdSchema);
136
+ }
137
+ async verify(data) {
138
+ }
139
+ };
140
+
141
+ // src/models/index.ts
142
+ var adModels = {
143
+ link: new LinkAdModel(),
144
+ cast: new CastAdModel(),
145
+ miniapp: new MiniAppAdModel()
146
+ };
147
+ function getAdModel(type) {
148
+ return adModels[type];
149
+ }
150
+
151
+ // src/types/index.ts
152
+ var adTypes = ["link", "cast", "miniapp"];
153
+
154
+ exports.AdModel = AdModel;
155
+ exports.CastAdModel = CastAdModel;
156
+ exports.DataModel = DataModel;
157
+ exports.LinkAdModel = LinkAdModel;
158
+ exports.MiniAppAdModel = MiniAppAdModel;
159
+ exports.adDataSchema = adDataSchema;
160
+ exports.adModels = adModels;
161
+ exports.adSchemas = adSchemas;
162
+ exports.adTypes = adTypes;
163
+ exports.castAdSchema = castAdSchema;
164
+ exports.getAdModel = getAdModel;
165
+ exports.getAdSchema = getAdSchema;
166
+ exports.getAllAdSchemas = getAllAdSchemas;
167
+ exports.linkAdSchema = linkAdSchema;
168
+ exports.miniappAdSchema = miniappAdSchema;
169
+ exports.validateAdData = validateAdData;
170
+ //# sourceMappingURL=index.cjs.map
171
+ //# 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/models/CastAdModel.ts","../src/models/MiniAppAdModel.ts","../src/models/index.ts","../src/types/index.ts"],"names":["z"],"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;AACj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\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 await this.verify(parsed);\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, AdData } 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 // Override to add custom verification\n // Example: check if URL is accessible\n // const response = await fetch(data.data.url, { method: \"HEAD\" });\n // if (!response.ok) throw new Error(\"URL is not accessible\");\n }\n}\n","import { AdModel } from \"./AdModel\";\nimport { castAdSchema } from \"../schemas\";\nimport type { CastAd } from \"../types\";\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: CastAd): Promise<void> {\n // Override to add custom verification\n // Example: verify it's a valid Warpcast URL\n // if (!data.data.url.includes(\"warpcast.com\")) {\n // throw new Error(\"Must be a valid Farcaster cast URL\");\n // }\n }\n}\n","import { AdModel } from \"./AdModel\";\nimport { miniappAdSchema } from \"../schemas\";\nimport type { MiniAppAd } from \"../types\";\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 // Override to add custom verification\n // Example: verify URL is actually a miniapp\n // const response = await fetch(data.data.url);\n // const html = await response.text();\n // if (!html.includes('property=\"fc:frame\"')) {\n // throw new Error(\"URL does not contain Farcaster frame metadata\");\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,229 @@
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: CastAd): Promise<void>;
205
+ }
206
+
207
+ /**
208
+ * MiniApp Ad Model
209
+ */
210
+ declare class MiniAppAdModel extends AdModel<MiniAppAd> {
211
+ readonly type: "miniapp";
212
+ constructor();
213
+ verify(data: MiniAppAd): Promise<void>;
214
+ }
215
+
216
+ /**
217
+ * Registry of all ad models
218
+ */
219
+ declare const adModels: {
220
+ readonly link: LinkAdModel;
221
+ readonly cast: CastAdModel;
222
+ readonly miniapp: MiniAppAdModel;
223
+ };
224
+ /**
225
+ * Get ad model for a specific type
226
+ */
227
+ declare function getAdModel<T extends "link" | "cast" | "miniapp">(type: T): T extends "link" ? LinkAdModel : T extends "cast" ? CastAdModel : T extends "miniapp" ? MiniAppAdModel : never;
228
+
229
+ 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,229 @@
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: CastAd): Promise<void>;
205
+ }
206
+
207
+ /**
208
+ * MiniApp Ad Model
209
+ */
210
+ declare class MiniAppAdModel extends AdModel<MiniAppAd> {
211
+ readonly type: "miniapp";
212
+ constructor();
213
+ verify(data: MiniAppAd): Promise<void>;
214
+ }
215
+
216
+ /**
217
+ * Registry of all ad models
218
+ */
219
+ declare const adModels: {
220
+ readonly link: LinkAdModel;
221
+ readonly cast: CastAdModel;
222
+ readonly miniapp: MiniAppAdModel;
223
+ };
224
+ /**
225
+ * Get ad model for a specific type
226
+ */
227
+ declare function getAdModel<T extends "link" | "cast" | "miniapp">(type: T): T extends "link" ? LinkAdModel : T extends "cast" ? CastAdModel : T extends "miniapp" ? MiniAppAdModel : never;
228
+
229
+ 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,154 @@
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
+ await this.verify(parsed);
73
+ return parsed;
74
+ }
75
+ /**
76
+ * Safe validation that returns result instead of throwing
77
+ */
78
+ async safeValidate(input) {
79
+ const result = await this.schema.safeParseAsync(input);
80
+ if (result.success) {
81
+ return { success: true, data: result.data };
82
+ }
83
+ return { success: false, error: result.error };
84
+ }
85
+ /**
86
+ * Safe prepare that returns result instead of throwing
87
+ */
88
+ async safePrepare(input) {
89
+ const validation = await this.safeValidate(input);
90
+ if (!validation.success) {
91
+ return validation;
92
+ }
93
+ try {
94
+ await this.verify(validation.data);
95
+ return { success: true, data: validation.data };
96
+ } catch (error) {
97
+ return {
98
+ success: false,
99
+ error: error instanceof Error ? error.message : "Verification failed"
100
+ };
101
+ }
102
+ }
103
+ };
104
+
105
+ // src/models/AdModel.ts
106
+ var AdModel = class extends DataModel {
107
+ };
108
+
109
+ // src/models/LinkAdModel.ts
110
+ var LinkAdModel = class extends AdModel {
111
+ type = "link";
112
+ constructor() {
113
+ super(linkAdSchema);
114
+ }
115
+ async verify(data) {
116
+ }
117
+ };
118
+
119
+ // src/models/CastAdModel.ts
120
+ var CastAdModel = class extends AdModel {
121
+ type = "cast";
122
+ constructor() {
123
+ super(castAdSchema);
124
+ }
125
+ async verify(data) {
126
+ }
127
+ };
128
+
129
+ // src/models/MiniAppAdModel.ts
130
+ var MiniAppAdModel = class extends AdModel {
131
+ type = "miniapp";
132
+ constructor() {
133
+ super(miniappAdSchema);
134
+ }
135
+ async verify(data) {
136
+ }
137
+ };
138
+
139
+ // src/models/index.ts
140
+ var adModels = {
141
+ link: new LinkAdModel(),
142
+ cast: new CastAdModel(),
143
+ miniapp: new MiniAppAdModel()
144
+ };
145
+ function getAdModel(type) {
146
+ return adModels[type];
147
+ }
148
+
149
+ // src/types/index.ts
150
+ var adTypes = ["link", "cast", "miniapp"];
151
+
152
+ export { AdModel, CastAdModel, DataModel, LinkAdModel, MiniAppAdModel, adDataSchema, adModels, adSchemas, adTypes, castAdSchema, getAdModel, getAdSchema, getAllAdSchemas, linkAdSchema, miniappAdSchema, validateAdData };
153
+ //# sourceMappingURL=index.js.map
154
+ //# 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/models/CastAdModel.ts","../src/models/MiniAppAdModel.ts","../src/models/index.ts","../src/types/index.ts"],"names":[],"mappings":";;;AAKA,IAAM,gBAAA,GAAmB,EAAE,MAAA,CAAO;AAAA,EAChC,GAAA,EAAK,CAAA,CAAE,MAAA,EAAO,CAAE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AAA,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 await this.verify(parsed);\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, AdData } 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 // Override to add custom verification\n // Example: check if URL is accessible\n // const response = await fetch(data.data.url, { method: \"HEAD\" });\n // if (!response.ok) throw new Error(\"URL is not accessible\");\n }\n}\n","import { AdModel } from \"./AdModel\";\nimport { castAdSchema } from \"../schemas\";\nimport type { CastAd } from \"../types\";\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: CastAd): Promise<void> {\n // Override to add custom verification\n // Example: verify it's a valid Warpcast URL\n // if (!data.data.url.includes(\"warpcast.com\")) {\n // throw new Error(\"Must be a valid Farcaster cast URL\");\n // }\n }\n}\n","import { AdModel } from \"./AdModel\";\nimport { miniappAdSchema } from \"../schemas\";\nimport type { MiniAppAd } from \"../types\";\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 // Override to add custom verification\n // Example: verify URL is actually a miniapp\n // const response = await fetch(data.data.url);\n // const html = await response.text();\n // if (!html.includes('property=\"fc:frame\"')) {\n // throw new Error(\"URL does not contain Farcaster frame metadata\");\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.2.0",
3
+ "version": "0.4.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": "^3.24.2"
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,35 +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
- };
35
-
package/src/index.ts DELETED
@@ -1,24 +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
- SwapAd,
10
- } from "./types";
11
-
12
- // Export Zod schemas
13
- export {
14
- linkAdSchema,
15
- castAdSchema,
16
- miniappAdSchema,
17
- tokenAdSchema,
18
- swapAdSchema,
19
- adDataSchema,
20
- adSchemas,
21
- getAdSchema,
22
- getAllAdSchemas,
23
- validateAdData,
24
- } from "./schemas";
@@ -1,94 +0,0 @@
1
- import { z } from "zod";
2
-
3
- /**
4
- * Link ad schema - basic link
5
- */
6
- export const linkAdSchema = z.object({
7
- type: z.literal("link"),
8
- url: z.string().url("Must be a valid URL"),
9
- });
10
-
11
- /**
12
- * Cast ad schema - link to a Farcaster cast
13
- */
14
- export const castAdSchema = z.object({
15
- type: z.literal("cast"),
16
- url: z.string().url("Must be a valid URL"),
17
- });
18
-
19
- /**
20
- * MiniApp ad schema - link to a Farcaster mini app
21
- */
22
- export const miniappAdSchema = z.object({
23
- type: z.literal("miniapp"),
24
- url: z.string().url("Must be a valid URL"),
25
- });
26
-
27
- /**
28
- * Token ad schema - token information
29
- */
30
- export const tokenAdSchema = z.object({
31
- type: z.literal("token"),
32
- token: z.string().min(1, "Token is required"),
33
- });
34
-
35
- /**
36
- * Swap ad schema - token swap information
37
- */
38
- export const swapAdSchema = z.object({
39
- type: z.literal("swap"),
40
- fromToken: z.string().min(1, "From token is required"),
41
- toToken: z.string().min(1, "To token is required"),
42
- amount: z.string().optional(),
43
- });
44
-
45
- /**
46
- * Union schema for all ad types
47
- */
48
- export const adDataSchema = z.discriminatedUnion("type", [
49
- linkAdSchema,
50
- castAdSchema,
51
- miniappAdSchema,
52
- tokenAdSchema,
53
- swapAdSchema,
54
- ]);
55
-
56
- /**
57
- * All ad schemas as an object
58
- */
59
- export const adSchemas = {
60
- link: linkAdSchema,
61
- cast: castAdSchema,
62
- miniapp: miniappAdSchema,
63
- token: tokenAdSchema,
64
- swap: swapAdSchema,
65
- } as const;
66
-
67
- /**
68
- * Get schema for a specific ad type
69
- */
70
- export function getAdSchema(type: keyof typeof adSchemas) {
71
- return adSchemas[type];
72
- }
73
-
74
- /**
75
- * Get all ad schemas
76
- */
77
- export function getAllAdSchemas() {
78
- return adSchemas;
79
- }
80
-
81
- /**
82
- * Validate ad data
83
- */
84
- export function validateAdData(data: unknown): {
85
- success: boolean;
86
- data?: z.infer<typeof adDataSchema>;
87
- error?: z.ZodError;
88
- } {
89
- const result = adDataSchema.safeParse(data);
90
- if (result.success) {
91
- return { success: true, data: result.data };
92
- }
93
- return { success: false, error: result.error };
94
- }
@@ -1,44 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- linkAdSchema,
4
- castAdSchema,
5
- miniappAdSchema,
6
- tokenAdSchema,
7
- swapAdSchema,
8
- adDataSchema,
9
- } from "../schemas";
10
-
11
- /**
12
- * Base ad type
13
- */
14
- export type AdType = "link" | "cast" | "miniapp" | "token" | "swap";
15
-
16
- /**
17
- * Link ad type - basic link
18
- */
19
- export type LinkAd = z.infer<typeof linkAdSchema>;
20
-
21
- /**
22
- * Cast ad type - link to a Farcaster cast
23
- */
24
- export type CastAd = z.infer<typeof castAdSchema>;
25
-
26
- /**
27
- * MiniApp ad type - link to a Farcaster mini app
28
- */
29
- export type MiniAppAd = z.infer<typeof miniappAdSchema>;
30
-
31
- /**
32
- * Token ad type - token information
33
- */
34
- export type TokenAd = z.infer<typeof tokenAdSchema>;
35
-
36
- /**
37
- * Swap ad type - token swap information
38
- */
39
- export type SwapAd = z.infer<typeof swapAdSchema>;
40
-
41
- /**
42
- * Union type of all ad types
43
- */
44
- 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
-