@builder.io/sdk-svelte 0.7.0 → 0.7.1-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 (81) hide show
  1. package/lib/browser/blocks/custom-code/custom-code.svelte +35 -37
  2. package/lib/browser/components/content/components/enable-editor.svelte +82 -65
  3. package/lib/browser/components/content/components/enable-editor.svelte.d.ts +3 -3
  4. package/lib/browser/constants/sdk-version.d.ts +1 -1
  5. package/lib/browser/constants/sdk-version.js +1 -1
  6. package/lib/browser/functions/evaluate/choose-eval.d.ts +6 -0
  7. package/lib/browser/functions/evaluate/choose-eval.js +19 -0
  8. package/lib/browser/functions/evaluate/evaluate.d.ts +1 -5
  9. package/lib/browser/functions/evaluate/evaluate.js +7 -30
  10. package/lib/browser/functions/evaluate/helpers.d.ts +7 -1
  11. package/lib/browser/functions/evaluate/helpers.js +18 -0
  12. package/lib/browser/functions/evaluate/node-runtime/index.d.ts +1 -1
  13. package/lib/browser/functions/evaluate/node-runtime/index.js +1 -1
  14. package/lib/browser/functions/evaluate/node-runtime/node-runtime.d.ts +2 -0
  15. package/lib/browser/functions/evaluate/node-runtime/node-runtime.js +120 -0
  16. package/lib/browser/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +13 -0
  17. package/lib/browser/functions/evaluate/node-runtime/safeDynamicRequire.js +18 -0
  18. package/lib/browser/functions/get-content/generate-content-url.js +27 -1
  19. package/lib/browser/functions/get-content/types.d.ts +94 -3
  20. package/lib/browser/functions/is-edge-runtime.js +2 -2
  21. package/lib/browser/functions/is-node-runtime.d.ts +4 -0
  22. package/lib/browser/functions/is-node-runtime.js +7 -0
  23. package/lib/edge/blocks/custom-code/custom-code.svelte +35 -37
  24. package/lib/edge/components/content/components/enable-editor.svelte +82 -65
  25. package/lib/edge/components/content/components/enable-editor.svelte.d.ts +3 -3
  26. package/lib/edge/constants/sdk-version.d.ts +1 -1
  27. package/lib/edge/constants/sdk-version.js +1 -1
  28. package/lib/edge/functions/evaluate/choose-eval.d.ts +6 -0
  29. package/lib/edge/functions/evaluate/choose-eval.js +19 -0
  30. package/lib/edge/functions/evaluate/evaluate.d.ts +1 -5
  31. package/lib/edge/functions/evaluate/evaluate.js +7 -30
  32. package/lib/edge/functions/evaluate/helpers.d.ts +7 -1
  33. package/lib/edge/functions/evaluate/helpers.js +18 -0
  34. package/lib/edge/functions/evaluate/node-runtime/index.d.ts +1 -1
  35. package/lib/edge/functions/evaluate/node-runtime/index.js +1 -1
  36. package/lib/edge/functions/evaluate/node-runtime/node-runtime.d.ts +2 -0
  37. package/lib/edge/functions/evaluate/node-runtime/node-runtime.js +120 -0
  38. package/lib/edge/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +13 -0
  39. package/lib/edge/functions/evaluate/node-runtime/safeDynamicRequire.js +18 -0
  40. package/lib/edge/functions/get-content/generate-content-url.js +27 -1
  41. package/lib/edge/functions/get-content/types.d.ts +94 -3
  42. package/lib/edge/functions/is-edge-runtime.js +2 -2
  43. package/lib/edge/functions/is-node-runtime.d.ts +4 -0
  44. package/lib/edge/functions/is-node-runtime.js +7 -0
  45. package/lib/node/blocks/custom-code/custom-code.svelte +35 -37
  46. package/lib/node/components/content/components/enable-editor.svelte +82 -65
  47. package/lib/node/components/content/components/enable-editor.svelte.d.ts +3 -3
  48. package/lib/node/constants/sdk-version.d.ts +1 -1
  49. package/lib/node/constants/sdk-version.js +1 -1
  50. package/lib/node/functions/evaluate/choose-eval.d.ts +6 -0
  51. package/lib/node/functions/evaluate/choose-eval.js +19 -0
  52. package/lib/node/functions/evaluate/evaluate.d.ts +1 -5
  53. package/lib/node/functions/evaluate/evaluate.js +7 -30
  54. package/lib/node/functions/evaluate/helpers.d.ts +7 -1
  55. package/lib/node/functions/evaluate/helpers.js +18 -0
  56. package/lib/node/functions/evaluate/node-runtime/index.d.ts +1 -1
  57. package/lib/node/functions/evaluate/node-runtime/index.js +1 -1
  58. package/lib/node/functions/evaluate/node-runtime/node-runtime.d.ts +2 -0
  59. package/lib/node/functions/evaluate/node-runtime/node-runtime.js +120 -0
  60. package/lib/node/functions/evaluate/node-runtime/safeDynamicRequire.d.ts +13 -0
  61. package/lib/node/functions/evaluate/node-runtime/safeDynamicRequire.js +18 -0
  62. package/lib/node/functions/get-content/generate-content-url.js +27 -1
  63. package/lib/node/functions/get-content/types.d.ts +94 -3
  64. package/lib/node/functions/is-edge-runtime.js +2 -2
  65. package/lib/node/functions/is-node-runtime.d.ts +4 -0
  66. package/lib/node/functions/is-node-runtime.js +7 -0
  67. package/package.json +2 -1
  68. package/src/blocks/custom-code/custom-code.svelte +37 -40
  69. package/src/blocks/image/image.svelte +1 -1
  70. package/src/components/content/components/enable-editor.svelte +97 -79
  71. package/src/constants/sdk-version.ts +1 -1
  72. package/src/functions/evaluate/choose-eval.ts +22 -0
  73. package/src/functions/evaluate/evaluate.ts +8 -37
  74. package/src/functions/evaluate/helpers.ts +24 -1
  75. package/src/functions/evaluate/node-runtime/index.ts +1 -1
  76. package/src/functions/evaluate/node-runtime/node-runtime.ts +138 -0
  77. package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +18 -0
  78. package/src/functions/get-content/generate-content-url.ts +36 -1
  79. package/src/functions/get-content/types.ts +101 -3
  80. package/src/functions/is-edge-runtime.ts +2 -2
  81. package/src/functions/is-node-runtime.ts +8 -0
@@ -8,12 +8,44 @@ export interface GetContentOptions {
8
8
  /** Number of items to fetch. Default is 1 */
9
9
  limit?: number;
10
10
 
11
- /** User attributes to target on, such as { urlPath: '/foo', device: 'mobile', ...etc } */
11
+ /**
12
+ * Use to specify an offset for pagination of results. The default is 0.
13
+ */
14
+ offset?: number;
15
+
16
+ /**
17
+ * User attribute key value pairs to be used for targeting
18
+ * https://www.builder.io/c/docs/custom-targeting-attributes
19
+ *
20
+ * e.g.
21
+ * ```js
22
+ * userAttributes: {
23
+ * urlPath: '/',
24
+ * returnVisitor: true,
25
+ * device: 'mobile'
26
+ * }
27
+ * ```
28
+ */
12
29
  userAttributes?: (Record<string, string> & {
13
30
  urlPath?: string;
14
31
  }) | null;
15
32
 
16
- /** Custom query */
33
+ /**
34
+ * Mongodb style query of your data. E.g.:
35
+ *
36
+ * ```js
37
+ * query: {
38
+ * id: 'abc123',
39
+ * data: {
40
+ * myCustomField: { $gt: 20 },
41
+ * }
42
+ * }
43
+ * ```
44
+ *
45
+ * See more info on MongoDB's query operators and format.
46
+ *
47
+ * @see {@link https://docs.mongodb.com/manual/reference/operator/query/}
48
+ */
17
49
  query?: Record<string, any>;
18
50
 
19
51
  /**
@@ -38,7 +70,7 @@ export interface GetContentOptions {
38
70
  canTrack?: boolean;
39
71
 
40
72
  /**
41
- * Include references in the response. Defaults to `true`.
73
+ * Include content of references in the response. Defaults to `true`.
42
74
  * @deprecated use `enrich` instead
43
75
  */
44
76
  includeRefs?: boolean;
@@ -59,4 +91,70 @@ export interface GetContentOptions {
59
91
  * Defaults to `v3`.
60
92
  */
61
93
  apiVersion?: 'v2' | 'v3';
94
+
95
+ /**
96
+ * Only include these fields.
97
+ * Note: 'omit' takes precedence over 'fields'
98
+ *
99
+ * @example
100
+ * ```
101
+ * fields: 'id, name, data.customField'
102
+ * ```
103
+ */
104
+ fields?: string;
105
+
106
+ /**
107
+ * Omit only these fields.
108
+ * Note: 'omit' takes precedence over 'fields'
109
+ *
110
+ * @example
111
+ * ```
112
+ * omit: 'data.bigField,data.blocks'
113
+ * ```
114
+ */
115
+ omit?: string;
116
+
117
+ /**
118
+ * Seconds to cache content. Sets the max-age of the cache-control header
119
+ * response header.
120
+ *
121
+ * Use a higher value for better performance, lower for content that will change more frequently
122
+ *
123
+ * @see {@link https://www.builder.io/c/docs/query-api#__next:~:text=%26includeRefs%3Dtrue-,cacheSeconds,-No}
124
+ */
125
+ cacheSeconds?: number;
126
+
127
+ /**
128
+ * Builder.io uses stale-while-revalidate caching at the CDN level. This means we always serve
129
+ * from edge cache and update caches in the background for maximum possible performance. This also
130
+ * means that the more frequently content is requested, the more fresh it will be. The longest we
131
+ * will ever hold something in stale cache is 1 day by default, and you can set this to be shorter
132
+ * yourself as well. We suggest keeping this high unless you have content that must change rapidly
133
+ * and gets very little traffic.
134
+ *
135
+ * @see {@link https://www.fastly.com/blog/prevent-application-network-instability-serve-stale-content}
136
+ */
137
+ staleCacheSeconds?: number;
138
+
139
+ /**
140
+ * Property to order results by.
141
+ * Use 1 for ascending and -1 for descending.
142
+ *
143
+ * The key is what you're sorting on, so the following example sorts by createdDate
144
+ * and because the value is 1, the sort is ascending.
145
+ *
146
+ * @example
147
+ * ```
148
+ * createdDate: 1
149
+ * ```
150
+ */
151
+ sort?: {
152
+ [key: string]: 1 | -1;
153
+ };
154
+
155
+ /**
156
+ * Include content entries in a response that are still in
157
+ * draft mode and un-archived. Default is false.
158
+ */
159
+ includeUnpublished?: boolean;
62
160
  }
@@ -1,9 +1,9 @@
1
1
  import { isBrowser } from './is-browser.js';
2
+ import { isNodeRuntime } from './is-node-runtime.js';
2
3
 
3
4
  /**
4
5
  * Identifies edge runtimes (edge, workers, serverless, etc.)
5
6
  */
6
7
  export function isEdgeRuntime(): boolean {
7
- const hasNode = () => typeof process !== 'undefined' && process?.versions?.node;
8
- return !isBrowser() && !hasNode();
8
+ return !isBrowser() && !isNodeRuntime();
9
9
  }
@@ -0,0 +1,8 @@
1
+ import { checkIsDefined } from '../helpers/nullable';
2
+
3
+ /**
4
+ * Identifies node runtime
5
+ */
6
+ export function isNodeRuntime(): boolean {
7
+ return typeof process !== 'undefined' && checkIsDefined(process?.versions?.node);
8
+ }