graze-client 0.8.0 → 0.9.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.
Files changed (45) hide show
  1. package/build/dts/GrazeClient.d.ts +368 -242
  2. package/build/dts/GrazeClient.d.ts.map +1 -1
  3. package/build/dts/builder.d.ts +8 -8
  4. package/build/dts/builder.d.ts.map +1 -1
  5. package/build/dts/common.d.ts +2 -3
  6. package/build/dts/common.d.ts.map +1 -1
  7. package/build/dts/index.d.ts +13 -13
  8. package/build/dts/index.d.ts.map +1 -1
  9. package/build/dts/schema/Post.d.ts +52 -52
  10. package/build/dts/schema/StickyPosts.d.ts +55 -56
  11. package/build/dts/schema/StickyPosts.d.ts.map +1 -1
  12. package/build/dts/schema/UpdateAlgorithmPayload.d.ts +187 -163
  13. package/build/dts/schema/UpdateAlgorithmPayload.d.ts.map +1 -1
  14. package/build/dts/schema/shared.d.ts +127 -127
  15. package/build/dts/schema/shared.d.ts.map +1 -1
  16. package/build/dts/stickyposts.d.ts +80 -78
  17. package/build/dts/stickyposts.d.ts.map +1 -1
  18. package/build/esm/GrazeClient.js +45 -29
  19. package/build/esm/GrazeClient.js.map +1 -1
  20. package/build/esm/builder.js +2 -2
  21. package/build/esm/builder.js.map +1 -1
  22. package/build/esm/common.js +4 -3
  23. package/build/esm/common.js.map +1 -1
  24. package/build/esm/index.js +8 -5
  25. package/build/esm/index.js.map +1 -1
  26. package/build/esm/schema/Post.js +6 -6
  27. package/build/esm/schema/Post.js.map +1 -1
  28. package/build/esm/schema/StickyPosts.js +2 -3
  29. package/build/esm/schema/StickyPosts.js.map +1 -1
  30. package/build/esm/schema/UpdateAlgorithmPayload.js +116 -39
  31. package/build/esm/schema/UpdateAlgorithmPayload.js.map +1 -1
  32. package/build/esm/schema/shared.js +6 -6
  33. package/build/esm/schema/shared.js.map +1 -1
  34. package/build/esm/stickyposts.js +28 -13
  35. package/build/esm/stickyposts.js.map +1 -1
  36. package/package.json +8 -10
  37. package/src/GrazeClient.ts +55 -47
  38. package/src/builder.ts +14 -14
  39. package/src/common.ts +4 -9
  40. package/src/index.ts +24 -19
  41. package/src/schema/Post.ts +6 -6
  42. package/src/schema/StickyPosts.ts +3 -7
  43. package/src/schema/UpdateAlgorithmPayload.ts +80 -67
  44. package/src/schema/shared.ts +6 -6
  45. package/src/stickyposts.ts +44 -23
@@ -5,30 +5,43 @@ import { Schema as S } from "effect";
5
5
  export const ListUri = S.String;
6
6
  export type ListUri = typeof ListUri.Type;
7
7
 
8
- export const AttributeName = S.Union(
8
+ export const AttributeName = S.Union([
9
9
  S.Literal("text"),
10
10
  S.Literal("reply"),
11
11
  S.Literal("embed.images[*].alt"),
12
+ S.Literal("embed.media.images[*].alt"),
12
13
  S.Literal("embed.alt"),
13
14
  S.Literal("embed"),
14
15
  S.Literal("embed.external.uri"),
15
16
  S.Literal("embed.external.title"),
16
17
  S.Literal("embed.external.description"),
17
- S.Literal("embed.images[*].alt"),
18
18
  S.Literal("embed.media.external.uri"),
19
19
  S.Literal("embed.media.external.title"),
20
20
  S.Literal("embed.media.external.description"),
21
21
  S.Literal("embed.record.uri"),
22
- S.Literal("langs[*"),
22
+ S.Literal("langs[*]"),
23
23
  S.Literal("labels.values[*].val"),
24
- S.Literal("facets[*].features[*].uri")
25
- );
24
+ S.Literal("facets[*].features[*].uri"),
25
+ S.Literal("hydrated_metadata.user.did"),
26
+ S.Literal("hydrated_metadata.user.handle"),
27
+ S.Literal("hydrated_metadata.user.description"),
28
+ S.Literal("hydrated_metadata.user.display_name"),
29
+ S.Literal("hydrated_metadata.user.labels"),
30
+ S.Literal("hydrated_metadata.mentions.display_name"),
31
+ ]);
26
32
  export type AttributeName = typeof AttributeName.Type;
27
- export const AttributeComparison = S.Literal("==", "!=", ">", "<", ">=", "<=");
33
+ export const AttributeComparison = S.Literals([
34
+ "==",
35
+ "!=",
36
+ ">",
37
+ "<",
38
+ ">=",
39
+ "<=",
40
+ ]);
28
41
  export type AttributeComparison = typeof AttributeComparison.Type;
29
42
  export const AttributeValue = S.Null;
30
43
  export type AttributeValue = typeof AttributeValue.Type;
31
- export const PostType = S.Literal("reply", "quote");
44
+ export const PostType = S.Literals(["reply", "quote"]);
32
45
  export type PostType = typeof PostType.Type;
33
46
 
34
47
  // ------------------- Filters ------------------------------------
@@ -60,7 +73,7 @@ export type AttributeCompare = Readonly<{
60
73
  attribute_compare: readonly [
61
74
  AttributeName,
62
75
  AttributeComparison,
63
- AttributeValue
76
+ AttributeValue,
64
77
  ];
65
78
  }>;
66
79
  export type RegexMatches = Readonly<{
@@ -70,10 +83,10 @@ export type RegexNegationMatches = Readonly<{
70
83
  regex_negation_matches: readonly [AttributeName, string, boolean];
71
84
  }>;
72
85
  export type TextMatchesAny = Readonly<{
73
- regex_any: readonly [AttributeName, readonly string[], boolean, boolean];
86
+ regex_any: readonly [AttributeName, ReadonlyArray<string>, boolean, boolean];
74
87
  }>;
75
88
  export type TextMatchesNone = Readonly<{
76
- regex_none: readonly [AttributeName, readonly string[], boolean, boolean];
89
+ regex_none: readonly [AttributeName, ReadonlyArray<string>, boolean, boolean];
77
90
  }>;
78
91
  export type ContentModerationBlock = Readonly<{
79
92
  content_moderation: readonly ["OK", ">=", number];
@@ -84,77 +97,77 @@ export type EntityExcludesLabels = Readonly<{
84
97
  export type EmbedType = Readonly<{
85
98
  embed_type: readonly [
86
99
  "==" | "!=",
87
- "video" | "image" | "link" | "post" | "gif" | "image_group"
100
+ "video" | "image" | "link" | "post" | "gif" | "image_group",
88
101
  ];
89
102
  }>;
90
103
  export type SocialGraph = Readonly<{
91
104
  social_graph: readonly [string, "in" | "not_in", "follows" | "followers"];
92
105
  }>;
93
106
 
94
- export const Filter = S.Union(
95
- S.suspend((): S.Schema<And> => And),
96
- S.suspend((): S.Schema<Or> => Or),
97
- S.suspend((): S.Schema<ListMemberFilter> => ListMemberFilter),
98
- S.suspend((): S.Schema<AttributeCompare> => AttributeCompare),
99
- S.suspend((): S.Schema<RegexMatches> => RegexMatches),
100
- S.suspend((): S.Schema<RegexNegationMatches> => RegexNegationMatches),
101
- S.suspend((): S.Schema<TextMatchesAny> => TextMatchesAny),
102
- S.suspend((): S.Schema<TextMatchesNone> => TextMatchesNone),
103
- S.suspend((): S.Schema<ContentModerationBlock> => ContentModerationBlock),
104
- S.suspend((): S.Schema<EntityExcludesLabels> => EntityExcludesLabels),
105
- S.suspend((): S.Schema<EmbedType> => EmbedType),
106
- S.suspend((): S.Schema<SocialGraph> => SocialGraph),
107
- S.suspend((): S.Schema<PostTypeFilter> => PostTypeFilter)
108
- );
107
+ export const Filter = S.Union([
108
+ S.suspend((): S.Codec<And> => And),
109
+ S.suspend((): S.Codec<Or> => Or),
110
+ S.suspend((): S.Codec<ListMemberFilter> => ListMemberFilter),
111
+ S.suspend((): S.Codec<AttributeCompare> => AttributeCompare),
112
+ S.suspend((): S.Codec<RegexMatches> => RegexMatches),
113
+ S.suspend((): S.Codec<RegexNegationMatches> => RegexNegationMatches),
114
+ S.suspend((): S.Codec<TextMatchesAny> => TextMatchesAny),
115
+ S.suspend((): S.Codec<TextMatchesNone> => TextMatchesNone),
116
+ S.suspend((): S.Codec<ContentModerationBlock> => ContentModerationBlock),
117
+ S.suspend((): S.Codec<EntityExcludesLabels> => EntityExcludesLabels),
118
+ S.suspend((): S.Codec<EmbedType> => EmbedType),
119
+ S.suspend((): S.Codec<SocialGraph> => SocialGraph),
120
+ S.suspend((): S.Codec<PostTypeFilter> => PostTypeFilter),
121
+ ]);
109
122
 
110
123
  export const Or = S.Struct({ or: S.Array(Filter) });
111
124
  export const And = S.Struct({ and: S.Array(Filter) });
112
125
  export const PostTypeFilter = S.Struct({
113
- post_type: S.Tuple(S.Literal("in", "not_in"), S.Array(PostType)),
126
+ post_type: S.Tuple([S.Literals(["in", "not_in"]), S.Array(PostType)]),
114
127
  });
115
128
  export const ListMemberFilter = S.Struct({
116
- list_member: S.Tuple(ListUri, S.Literal("in", "not_in")),
129
+ list_member: S.Tuple([ListUri, S.Literals(["in", "not_in"])]),
117
130
  });
118
131
  export const AttributeCompare = S.Struct({
119
- attribute_compare: S.Tuple(
132
+ attribute_compare: S.Tuple([
120
133
  AttributeName,
121
134
  AttributeComparison,
122
- AttributeValue
123
- ),
135
+ AttributeValue,
136
+ ]),
124
137
  });
125
- const RegexMatchBase = S.Tuple(
138
+ const RegexMatchBase = S.Tuple([
126
139
  AttributeName,
127
- S.String.annotations({
140
+ S.String.annotate({
128
141
  title: "Regex Pattern",
129
142
  description: "The source of the regex pattern to match against.",
130
143
  }),
131
- S.Boolean.annotations({
144
+ S.Boolean.annotate({
132
145
  title: "Case Insensitive?",
133
146
  description: "True if the regex should be case insensitive.",
134
- })
135
- );
147
+ }),
148
+ ]);
136
149
  export const RegexMatches = S.Struct({
137
150
  regex_matches: RegexMatchBase,
138
151
  });
139
152
  export const RegexNegationMatches = S.Struct({
140
153
  regex_negation_matches: RegexMatchBase,
141
154
  });
142
- const TextMatchBase = S.Tuple(
155
+ const TextMatchBase = S.Tuple([
143
156
  AttributeName,
144
- S.Array(S.String).annotations({
157
+ S.Array(S.String).annotate({
145
158
  title: "Text Patterns",
146
159
  description: "List of possible text patterns to match against.",
147
160
  }),
148
- S.Boolean.annotations({
161
+ S.Boolean.annotate({
149
162
  title: "Case Insensitive?",
150
163
  description: "True if the matching should be case insensitive.",
151
164
  }),
152
- S.Boolean.annotations({
165
+ S.Boolean.annotate({
153
166
  title: "Use Regex?",
154
167
  description:
155
168
  "True if the values should be treated as regex patterns, false for literal strings.",
156
- })
157
- );
169
+ }),
170
+ ]);
158
171
  export const TextMatchesAny = S.Struct({
159
172
  regex_any: TextMatchBase,
160
173
  });
@@ -162,33 +175,33 @@ export const TextMatchesNone = S.Struct({
162
175
  regex_none: TextMatchBase,
163
176
  });
164
177
  export const ContentModerationBlock = S.Struct({
165
- content_moderation: S.Tuple(
178
+ content_moderation: S.Tuple([
166
179
  S.Literal("OK"),
167
180
  S.Literal(">="),
168
- S.Number.annotations({
181
+ S.Number.annotate({
169
182
  title: "Threshold",
170
183
  description: "The threshold for content moderation.",
171
- })
172
- ),
184
+ }),
185
+ ]),
173
186
  });
174
187
  export const EntityExcludesLabels = S.Struct({
175
- entity_excludes: S.Tuple(
188
+ entity_excludes: S.Tuple([
176
189
  S.Literal("labels"),
177
- S.Tuple(S.Literal("porn"), S.Literal("sexual"), S.Literal("nudity"))
178
- ),
190
+ S.Tuple([S.Literal("porn"), S.Literal("sexual"), S.Literal("nudity")]),
191
+ ]),
179
192
  });
180
193
  export const EmbedType = S.Struct({
181
- embed_type: S.Tuple(
182
- S.Literal("==", "!="),
183
- S.Literal("video", "image", "link", "post", "gif", "image_group")
184
- ),
194
+ embed_type: S.Tuple([
195
+ S.Literals(["==", "!="]),
196
+ S.Literals(["video", "image", "link", "post", "gif", "image_group"]),
197
+ ]),
185
198
  });
186
199
  export const SocialGraph = S.Struct({
187
- social_graph: S.Tuple(
200
+ social_graph: S.Tuple([
188
201
  S.String,
189
- S.Literal("in", "not_in"),
190
- S.Literal("follows", "followers")
191
- ),
202
+ S.Literals(["in", "not_in"]),
203
+ S.Literals(["follows", "followers"]),
204
+ ]),
192
205
  });
193
206
 
194
207
  // ---------------------- Sort Settings -----------------------------
@@ -207,28 +220,28 @@ export type SortSettings = typeof SortSettings.Type;
207
220
 
208
221
  // ---------------------- Form Data ---------------------------------
209
222
 
210
- export const DisplayName = S.String.annotations({
223
+ export const DisplayName = S.String.annotate({
211
224
  description: "The public name of the feed.",
212
225
  });
213
226
  export type DisplayName = typeof DisplayName.Type;
214
227
 
215
- export const RecordName = S.String.annotations({
228
+ export const RecordName = S.String.annotate({
216
229
  description: "The slug of the feed url.",
217
230
  });
218
231
  export type RecordName = typeof RecordName.Type;
219
232
 
220
- export const Description = S.String.annotations({
233
+ export const Description = S.String.annotate({
221
234
  description: "The description to be shown to users of the feed.",
222
235
  });
223
236
  export type Description = typeof Description.Type;
224
237
 
225
- export const Order = S.Union(
238
+ export const Order = S.Union([
226
239
  S.Literal("new"),
227
240
  S.Literal("trending"),
228
241
  S.Literal("blend"),
229
242
  S.Literal("hackernews"),
230
- S.Literal("old")
231
- );
243
+ S.Literal("old"),
244
+ ]);
232
245
  export type Order = typeof Order.Type;
233
246
 
234
247
  export const FeedId = S.NumberFromString;
@@ -248,8 +261,8 @@ export const Metadata = S.Struct({
248
261
  schema: S.optional(
249
262
  S.Struct({
250
263
  schemaVersion: S.Literal(2),
251
- sequences: S.Record({ key: S.String, value: S.Number }),
252
- })
264
+ sequences: S.Record(S.String, S.Number),
265
+ }),
253
266
  ),
254
267
  session: S.optional(S.Unknown),
255
268
  });
@@ -263,8 +276,8 @@ export const FullForm = S.Struct({
263
276
  record_name: RecordName,
264
277
  description: S.optional(Description),
265
278
  order: Order,
266
- algorithm_manifest: S.parseJson(AlgorithmManifest),
267
- metadata: S.optional(S.parseJson(Metadata)),
279
+ algorithm_manifest: S.fromJsonString(AlgorithmManifest),
280
+ metadata: S.optional(S.fromJsonString(Metadata)),
268
281
  });
269
282
  export type FullForm = typeof FullForm.Type;
270
283
  export type EncodedFullForm = typeof FullForm.Encoded;
@@ -2,25 +2,25 @@ import { Schema as S } from "effect";
2
2
 
3
3
  export const PartialAlgorithm = S.Struct({
4
4
  algorithm_uri: S.String,
5
- algorithm_manifest_id: S.Union(S.Null, S.Number),
5
+ algorithm_manifest_id: S.Union([S.Null, S.Number]),
6
6
  draft_algorithm_manifest_id: S.Number,
7
7
  record_name: S.String,
8
8
  display_name: S.String,
9
9
  description: S.String,
10
10
  feed_did: S.String,
11
- avatar_url: S.Union(S.String, S.Null),
12
- cpm_cents: S.Union(S.Number, S.Null),
11
+ avatar_url: S.Union([S.String, S.Null]),
12
+ cpm_cents: S.Union([S.Number, S.Null]),
13
13
  deleted: S.Boolean,
14
14
  active: S.Boolean,
15
15
  public: S.Boolean,
16
16
  monetization_available: S.Boolean,
17
- status: S.Union(S.String, S.Null),
17
+ status: S.Union([S.String, S.Null]),
18
18
  unique_operator_ids: S.Array(S.Number),
19
19
  user_id: S.Number,
20
20
  id: S.Number,
21
21
  created_at: S.DateFromString,
22
22
  updated_at: S.DateFromString,
23
- deleted_at: S.Union(S.DateFromString, S.Null),
23
+ deleted_at: S.Union([S.DateFromString, S.Null]),
24
24
  });
25
25
  export type PartialAlgorithm = typeof PartialAlgorithm.Type;
26
26
 
@@ -46,7 +46,7 @@ export const AlgoUpdateResponse = S.Struct({
46
46
  });
47
47
  export type AlgoUpdateResponse = typeof AlgoUpdateResponse.Type;
48
48
 
49
- export const GetAlgoResponse = S.parseJson(FullAlgorithmWithManifest);
49
+ export const GetAlgoResponse = S.fromJsonString(FullAlgorithmWithManifest);
50
50
  export type GetAlgoResponse = typeof GetAlgoResponse.Type;
51
51
 
52
52
  export const HidePostBody = S.Struct({
@@ -1,5 +1,5 @@
1
- import { HttpApiGroup, HttpApiEndpoint } from "@effect/platform";
2
- import { Schema } from "effect";
1
+ import { Schema, SchemaTransformation } from "effect";
2
+ import { FeedIdParam } from "./common.js";
3
3
  import {
4
4
  CreateStickyPostBody,
5
5
  GetStickyPostsBody,
@@ -7,37 +7,58 @@ import {
7
7
  StickyPostSuccess,
8
8
  StickyType,
9
9
  } from "./schema/StickyPosts.js";
10
- import { FeedIdParam } from "./common.js";
10
+ import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint";
11
+ import * as HttpApiGroup from "effect/unstable/httpapi/HttpApiGroup";
12
+
13
+ // v4 dropped `Schema.BooleanFromString`; decode the query strings "true"/"false".
14
+ const BooleanFromString = Schema.Literals(["true", "false"]).pipe(
15
+ Schema.decodeTo(
16
+ Schema.Boolean,
17
+ SchemaTransformation.transform({
18
+ decode: (s) => s === "true",
19
+ encode: (b) => (b ? "true" : "false"),
20
+ }),
21
+ ),
22
+ );
11
23
 
12
24
  export const StickyPostsApiGroup = HttpApiGroup.make("stickyposts")
13
25
  .add(
14
- HttpApiEndpoint.post("create")`/app/api/v1/feed-management/sticky-posts`
15
- .setPayload(CreateStickyPostBody)
16
- .addSuccess(StickyPostSuccess)
26
+ HttpApiEndpoint.post("create", "/app/api/v1/feed-management/sticky-posts", {
27
+ payload: CreateStickyPostBody,
28
+ success: StickyPostSuccess,
29
+ }),
17
30
  )
18
31
  .add(
19
32
  HttpApiEndpoint.get(
20
- "get"
21
- )`/app/api/v1/feed-management/sticky-posts/${FeedIdParam}`.addSuccess(
22
- GetStickyPostsBody
23
- )
33
+ "get",
34
+ "/app/api/v1/feed-management/sticky-posts/:feedId",
35
+ {
36
+ params: { feedId: FeedIdParam },
37
+ success: GetStickyPostsBody,
38
+ },
39
+ ),
24
40
  )
25
41
  .add(
26
42
  HttpApiEndpoint.put(
27
- "update"
28
- )`/app/api/v1/feed-management/sticky-posts/${FeedIdParam}/${StickyPostIdParam}`
29
- .setUrlParams(
30
- Schema.Struct({
31
- is_active: Schema.BooleanFromString,
43
+ "update",
44
+ "/app/api/v1/feed-management/sticky-posts/:feedId/:stickyPostId",
45
+ {
46
+ params: { feedId: FeedIdParam, stickyPostId: StickyPostIdParam },
47
+ query: Schema.Struct({
48
+ is_active: BooleanFromString,
32
49
  sticky_type: StickyType,
33
- })
34
- )
35
- .addSuccess(StickyPostSuccess)
50
+ }),
51
+ success: StickyPostSuccess,
52
+ },
53
+ ),
36
54
  )
37
55
  .add(
38
- HttpApiEndpoint.del(
39
- "delete"
40
- )`/app/api/v1/feed-management/sticky-posts/${FeedIdParam}/${StickyPostIdParam}`.addSuccess(
41
- StickyPostSuccess
42
- )
56
+ HttpApiEndpoint.make("DELETE")(
57
+ "delete",
58
+ "/app/api/v1/feed-management/sticky-posts/:feedId/:stickyPostId",
59
+ {
60
+ params: { feedId: FeedIdParam, stickyPostId: StickyPostIdParam },
61
+ success: StickyPostSuccess,
62
+ },
63
+ ),
43
64
  );