@notionhq/custom-blocks-host 0.1.24 → 0.1.26

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 (37) hide show
  1. package/README.md +13 -8
  2. package/dist/createCustomBlockHost.d.ts +8 -6
  3. package/dist/createCustomBlockHost.d.ts.map +1 -1
  4. package/dist/createCustomBlockHost.js +31 -18
  5. package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts +6 -0
  6. package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts.map +1 -0
  7. package/dist/lifecycle/normalizeHostToSandboxMessage.js +38 -0
  8. package/dist/protocol/dataSources/dataSource.d.ts +61 -6
  9. package/dist/protocol/dataSources/dataSource.js +35 -6
  10. package/dist/protocol/dataSources/propertySchema.d.ts +2 -0
  11. package/dist/protocol/dataSources/propertySchema.js +7 -0
  12. package/dist/protocol/messages/createPageResult.d.ts +1 -1
  13. package/dist/protocol/messages/getPage.d.ts +1 -1
  14. package/dist/protocol/messages/hostToSandbox.d.ts +10 -4
  15. package/dist/protocol/messages/init.d.ts +5 -2
  16. package/dist/protocol/messages/openPage.d.ts +1 -1
  17. package/dist/protocol/messages/pageChanged.d.ts +5 -2
  18. package/dist/protocol/messages/queryDataSource.d.ts +586 -485
  19. package/dist/protocol/messages/queryDataSource.js +61 -43
  20. package/dist/protocol/messages/queryDataSourceResult.d.ts +1 -1
  21. package/dist/protocol/messages/sandboxToHost.d.ts +212 -178
  22. package/dist/protocol/messages/updatePageResult.d.ts +1 -1
  23. package/dist/protocol/pages/page.d.ts +5 -2
  24. package/dist/protocol/pages/page.js +15 -9
  25. package/dist/protocol/protocolVersion.d.ts +1 -1
  26. package/dist/protocol/protocolVersion.js +1 -1
  27. package/dist/queries/validateQueryDataSourceFilter.d.ts +1 -1
  28. package/dist/queries/validateQueryDataSourceFilter.d.ts.map +1 -1
  29. package/dist/queries/validateQueryDataSourceFilter.js +11 -6
  30. package/dist/queries/validateQueryDataSourceSorts.d.ts +1 -1
  31. package/dist/queries/validateQueryDataSourceSorts.d.ts.map +1 -1
  32. package/dist/queries/validateQueryDataSourceSorts.js +3 -5
  33. package/package.json +1 -1
  34. package/src/createCustomBlockHost.ts +54 -31
  35. package/src/lifecycle/normalizeHostToSandboxMessage.ts +46 -0
  36. package/src/queries/validateQueryDataSourceFilter.ts +12 -7
  37. package/src/queries/validateQueryDataSourceSorts.ts +4 -10
@@ -1,119 +1,137 @@
1
1
  import * as v from "valibot";
2
2
  import { notionDataSourceIdSchema } from "../ids.js";
3
3
  const emptyOperatorSchema = v.union([
4
- v.object({ is_empty: v.literal(true) }),
5
- v.object({ is_not_empty: v.literal(true) }),
4
+ v.strictObject({ is_empty: v.literal(true) }),
5
+ v.strictObject({ is_not_empty: v.literal(true) }),
6
6
  ]);
7
7
  const stringOrStringArraySchema = v.union([v.string(), v.array(v.string())]);
8
- const customBlockPersonFilterValueSchema = v.object({
8
+ const customBlockPersonFilterValueSchema = v.strictObject({
9
9
  object: v.picklist(["user", "group"]),
10
10
  id: v.pipe(v.string(), v.minLength(1)),
11
11
  });
12
12
  export const customBlockPeopleFilterOperatorSchema = v.union([
13
- v.object({ contains: customBlockPersonFilterValueSchema }),
14
- v.object({ does_not_contain: customBlockPersonFilterValueSchema }),
13
+ v.strictObject({ contains: customBlockPersonFilterValueSchema }),
14
+ v.strictObject({ does_not_contain: customBlockPersonFilterValueSchema }),
15
15
  emptyOperatorSchema,
16
16
  ]);
17
+ /**
18
+ * Creator filters accept only human user targets.
19
+ * Returned creator values may refer to other actor types.
20
+ */
21
+ const customBlockCreatorFilterValueSchema = v.strictObject({
22
+ object: v.literal("user"),
23
+ id: v.pipe(v.string(), v.minLength(1), v.maxLength(2_000)),
24
+ });
25
+ export const customBlockCreatedByFilterOperatorSchema = v.union([
26
+ v.strictObject({ contains: customBlockCreatorFilterValueSchema }),
27
+ v.strictObject({ does_not_contain: customBlockCreatorFilterValueSchema }),
28
+ v.strictObject({ is_empty: v.literal(true) }),
29
+ v.strictObject({ is_not_empty: v.literal(true) }),
30
+ ]);
17
31
  export const customBlockTextFilterOperatorSchema = v.union([
18
- v.object({ equals: v.string() }),
19
- v.object({ does_not_equal: v.string() }),
20
- v.object({ contains: v.string() }),
21
- v.object({ does_not_contain: v.string() }),
22
- v.object({ starts_with: v.string() }),
23
- v.object({ ends_with: v.string() }),
32
+ v.strictObject({ equals: v.string() }),
33
+ v.strictObject({ does_not_equal: v.string() }),
34
+ v.strictObject({ contains: v.string() }),
35
+ v.strictObject({ does_not_contain: v.string() }),
36
+ v.strictObject({ starts_with: v.string() }),
37
+ v.strictObject({ ends_with: v.string() }),
24
38
  emptyOperatorSchema,
25
39
  ]);
26
40
  export const customBlockNumberFilterOperatorSchema = v.union([
27
- v.object({ equals: v.number() }),
28
- v.object({ does_not_equal: v.number() }),
29
- v.object({ greater_than: v.number() }),
30
- v.object({ less_than: v.number() }),
31
- v.object({ greater_than_or_equal_to: v.number() }),
32
- v.object({ less_than_or_equal_to: v.number() }),
41
+ v.strictObject({ equals: v.number() }),
42
+ v.strictObject({ does_not_equal: v.number() }),
43
+ v.strictObject({ greater_than: v.number() }),
44
+ v.strictObject({ less_than: v.number() }),
45
+ v.strictObject({ greater_than_or_equal_to: v.number() }),
46
+ v.strictObject({ less_than_or_equal_to: v.number() }),
33
47
  emptyOperatorSchema,
34
48
  ]);
35
49
  export const customBlockCheckboxFilterOperatorSchema = v.union([
36
- v.object({ equals: v.boolean() }),
37
- v.object({ does_not_equal: v.boolean() }),
50
+ v.strictObject({ equals: v.boolean() }),
51
+ v.strictObject({ does_not_equal: v.boolean() }),
38
52
  ]);
39
53
  export const customBlockOptionFilterOperatorSchema = v.union([
40
- v.object({ equals: stringOrStringArraySchema }),
41
- v.object({ does_not_equal: stringOrStringArraySchema }),
54
+ v.strictObject({ equals: stringOrStringArraySchema }),
55
+ v.strictObject({ does_not_equal: stringOrStringArraySchema }),
42
56
  emptyOperatorSchema,
43
57
  ]);
44
58
  export const customBlockContainsFilterOperatorSchema = v.union([
45
- v.object({ contains: stringOrStringArraySchema }),
46
- v.object({ contains_all: stringOrStringArraySchema }),
47
- v.object({ does_not_contain: stringOrStringArraySchema }),
59
+ v.strictObject({ contains: stringOrStringArraySchema }),
60
+ v.strictObject({ contains_all: stringOrStringArraySchema }),
61
+ v.strictObject({ does_not_contain: stringOrStringArraySchema }),
48
62
  emptyOperatorSchema,
49
63
  ]);
50
64
  export const customBlockDateFilterOperatorSchema = v.union([
51
- v.object({ equals: v.string() }),
52
- v.object({ before: v.string() }),
53
- v.object({ after: v.string() }),
54
- v.object({ on_or_before: v.string() }),
55
- v.object({ on_or_after: v.string() }),
65
+ v.strictObject({ equals: v.string() }),
66
+ v.strictObject({ before: v.string() }),
67
+ v.strictObject({ after: v.string() }),
68
+ v.strictObject({ on_or_before: v.string() }),
69
+ v.strictObject({ on_or_after: v.string() }),
56
70
  emptyOperatorSchema,
57
71
  ]);
58
72
  export const resolvedCustomBlockDataSourcePropertyFilterSchema = v.union([
59
- v.object({
73
+ v.strictObject({
74
+ propertyId: v.string(),
75
+ created_by: customBlockCreatedByFilterOperatorSchema,
76
+ }),
77
+ v.strictObject({
60
78
  propertyId: v.string(),
61
79
  title: customBlockTextFilterOperatorSchema,
62
80
  }),
63
- v.object({
81
+ v.strictObject({
64
82
  propertyId: v.string(),
65
83
  rich_text: customBlockTextFilterOperatorSchema,
66
84
  }),
67
- v.object({
85
+ v.strictObject({
68
86
  propertyId: v.string(),
69
87
  url: customBlockTextFilterOperatorSchema,
70
88
  }),
71
- v.object({
89
+ v.strictObject({
72
90
  propertyId: v.string(),
73
91
  email: customBlockTextFilterOperatorSchema,
74
92
  }),
75
- v.object({
93
+ v.strictObject({
76
94
  propertyId: v.string(),
77
95
  phone_number: customBlockTextFilterOperatorSchema,
78
96
  }),
79
- v.object({
97
+ v.strictObject({
80
98
  propertyId: v.string(),
81
99
  number: customBlockNumberFilterOperatorSchema,
82
100
  }),
83
- v.object({
101
+ v.strictObject({
84
102
  propertyId: v.string(),
85
103
  checkbox: customBlockCheckboxFilterOperatorSchema,
86
104
  }),
87
- v.object({
105
+ v.strictObject({
88
106
  propertyId: v.string(),
89
107
  select: customBlockOptionFilterOperatorSchema,
90
108
  }),
91
- v.object({
109
+ v.strictObject({
92
110
  propertyId: v.string(),
93
111
  multi_select: customBlockContainsFilterOperatorSchema,
94
112
  }),
95
- v.object({
113
+ v.strictObject({
96
114
  propertyId: v.string(),
97
115
  status: customBlockOptionFilterOperatorSchema,
98
116
  }),
99
- v.object({
117
+ v.strictObject({
100
118
  propertyId: v.string(),
101
119
  date: customBlockDateFilterOperatorSchema,
102
120
  }),
103
- v.object({
121
+ v.strictObject({
104
122
  propertyId: v.string(),
105
123
  people: customBlockPeopleFilterOperatorSchema,
106
124
  }),
107
125
  ]);
108
126
  export const resolvedCustomBlockDataSourceFilterSchema = v.union([
109
127
  resolvedCustomBlockDataSourcePropertyFilterSchema,
110
- v.object({
128
+ v.strictObject({
111
129
  and: v.array(resolvedCustomBlockDataSourcePropertyFilterSchema),
112
130
  }),
113
131
  ]);
114
132
  /** Maximum number of sort properties accepted in one data source query. */
115
133
  export const CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS = 10;
116
- export const resolvedCustomBlockDataSourceSortSchema = v.object({
134
+ export const resolvedCustomBlockDataSourceSortSchema = v.strictObject({
117
135
  propertyId: v.string(),
118
136
  direction: v.picklist(["ascending", "descending"]),
119
137
  });
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
2
  import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockQueryDataSourceErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockQueryDataSourceErrorCode = CustomBlockErrorCode<"query_data_source_failed" | "invalid_data_source_query" | "invalid_data_source_query_filter" | "invalid_data_source_query_sort" | "unknown_data_source_key" | "unmapped_data_source">;
4
+ export type CustomBlockQueryDataSourceErrorCode = CustomBlockErrorCode<"query_data_source_failed" | "invalid_data_source_query" | "invalid_data_source_query_filter" | "invalid_data_source_query_sort" | "unknown_data_source_key" | "unmapped_data_source" | "data_source_schema_unavailable">;
5
5
  export type CustomBlockQueryDataSourceErrorInfo = CustomBlockErrorInfo<CustomBlockQueryDataSourceErrorCode>;
6
6
  export declare const customBlockQueryDataSourceErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;