@builder.io/sdk-svelte 1.0.25 → 1.0.27

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.
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.25";
1
+ export declare const SDK_VERSION = "1.0.27";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.25";
1
+ export const SDK_VERSION = "1.0.27";
@@ -1,16 +1,3 @@
1
- /**
2
- * This file:
3
- * - imports `isolated-vm`, which can only be made from a file that never runs
4
- * on the client (e.g. Next's `_document.tsx`)
5
- * - stores the ivm instance in a global variable using `setIvm`
6
- *
7
- * This is needed for when bundlers/meta-frameworks are not able to reliably
8
- * import the `isolated-vm` package using our `safeDynamicRequire` trick.
9
- *
10
- * The `isolated-vm` import must exist in this separate file, or it will end up
11
- * in the SDK's main entry point, causing errors for users.
12
- */
13
- import ivm from 'isolated-vm';
14
1
  import type { IsolateOptions } from 'isolated-vm';
15
2
  /**
16
3
  * This function initializes the SDK on a Node server. It handles importing the
@@ -21,6 +8,6 @@ import type { IsolateOptions } from 'isolated-vm';
21
8
  * - The NextJS Pages router's `_document.tsx`
22
9
  * - Your Remix route's `loader`
23
10
  */
24
- export declare const initializeNodeRuntime: ({ ivmIsolateOptions }: {
25
- ivmIsolateOptions?: ivm.IsolateOptions | undefined;
11
+ export declare const initializeNodeRuntime: (args?: {
12
+ ivmIsolateOptions?: IsolateOptions;
26
13
  }) => void;
@@ -21,6 +21,7 @@ import { setIvm } from './node-runtime';
21
21
  * - The NextJS Pages router's `_document.tsx`
22
22
  * - Your Remix route's `loader`
23
23
  */
24
- export const initializeNodeRuntime = ({ ivmIsolateOptions }) => {
24
+ export const initializeNodeRuntime = (args) => {
25
+ const { ivmIsolateOptions } = args || {};
25
26
  setIvm(ivm, ivmIsolateOptions);
26
27
  };
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -59,7 +59,7 @@ export const generateContentUrl = (options) => {
59
59
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
60
60
  }
61
61
  if (query) {
62
- const flattened = flatten({
62
+ const flattened = flattenMongoQuery({
63
63
  query
64
64
  });
65
65
  for (const key in flattened) {
@@ -4,3 +4,13 @@
4
4
  * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
5
  */
6
6
  export declare function flatten<T extends Record<string, any>>(object: T, path?: string | null, separator?: string): T;
7
+ /**
8
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
9
+ * $ keys are not flattened and are left as is.
10
+ *
11
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
12
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
13
+ */
14
+ export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
15
+ [key: string]: string;
16
+ };
@@ -17,3 +17,23 @@ export function flatten(object, path = null, separator = '.') {
17
17
  };
18
18
  }, {});
19
19
  }
20
+ /**
21
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
22
+ * $ keys are not flattened and are left as is.
23
+ *
24
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
25
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
26
+ */
27
+ export function flattenMongoQuery(obj, _current, _res = {}) {
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ const newKey = _current ? _current + '.' + key : key;
31
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
32
+ flattenMongoQuery(value, newKey, _res);
33
+ }
34
+ else {
35
+ _res[newKey] = value;
36
+ }
37
+ }
38
+ return _res;
39
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.25";
1
+ export declare const SDK_VERSION = "1.0.27";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.25";
1
+ export const SDK_VERSION = "1.0.27";
@@ -1,16 +1,3 @@
1
- /**
2
- * This file:
3
- * - imports `isolated-vm`, which can only be made from a file that never runs
4
- * on the client (e.g. Next's `_document.tsx`)
5
- * - stores the ivm instance in a global variable using `setIvm`
6
- *
7
- * This is needed for when bundlers/meta-frameworks are not able to reliably
8
- * import the `isolated-vm` package using our `safeDynamicRequire` trick.
9
- *
10
- * The `isolated-vm` import must exist in this separate file, or it will end up
11
- * in the SDK's main entry point, causing errors for users.
12
- */
13
- import ivm from 'isolated-vm';
14
1
  import type { IsolateOptions } from 'isolated-vm';
15
2
  /**
16
3
  * This function initializes the SDK on a Node server. It handles importing the
@@ -21,6 +8,6 @@ import type { IsolateOptions } from 'isolated-vm';
21
8
  * - The NextJS Pages router's `_document.tsx`
22
9
  * - Your Remix route's `loader`
23
10
  */
24
- export declare const initializeNodeRuntime: ({ ivmIsolateOptions }: {
25
- ivmIsolateOptions?: ivm.IsolateOptions | undefined;
11
+ export declare const initializeNodeRuntime: (args?: {
12
+ ivmIsolateOptions?: IsolateOptions;
26
13
  }) => void;
@@ -21,6 +21,7 @@ import { setIvm } from './node-runtime';
21
21
  * - The NextJS Pages router's `_document.tsx`
22
22
  * - Your Remix route's `loader`
23
23
  */
24
- export const initializeNodeRuntime = ({ ivmIsolateOptions }) => {
24
+ export const initializeNodeRuntime = (args) => {
25
+ const { ivmIsolateOptions } = args || {};
25
26
  setIvm(ivm, ivmIsolateOptions);
26
27
  };
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -59,7 +59,7 @@ export const generateContentUrl = (options) => {
59
59
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
60
60
  }
61
61
  if (query) {
62
- const flattened = flatten({
62
+ const flattened = flattenMongoQuery({
63
63
  query
64
64
  });
65
65
  for (const key in flattened) {
@@ -4,3 +4,13 @@
4
4
  * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
5
  */
6
6
  export declare function flatten<T extends Record<string, any>>(object: T, path?: string | null, separator?: string): T;
7
+ /**
8
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
9
+ * $ keys are not flattened and are left as is.
10
+ *
11
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
12
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
13
+ */
14
+ export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
15
+ [key: string]: string;
16
+ };
@@ -17,3 +17,23 @@ export function flatten(object, path = null, separator = '.') {
17
17
  };
18
18
  }, {});
19
19
  }
20
+ /**
21
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
22
+ * $ keys are not flattened and are left as is.
23
+ *
24
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
25
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
26
+ */
27
+ export function flattenMongoQuery(obj, _current, _res = {}) {
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ const newKey = _current ? _current + '.' + key : key;
31
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
32
+ flattenMongoQuery(value, newKey, _res);
33
+ }
34
+ else {
35
+ _res[newKey] = value;
36
+ }
37
+ }
38
+ return _res;
39
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.25";
1
+ export declare const SDK_VERSION = "1.0.27";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.25";
1
+ export const SDK_VERSION = "1.0.27";
@@ -1,16 +1,3 @@
1
- /**
2
- * This file:
3
- * - imports `isolated-vm`, which can only be made from a file that never runs
4
- * on the client (e.g. Next's `_document.tsx`)
5
- * - stores the ivm instance in a global variable using `setIvm`
6
- *
7
- * This is needed for when bundlers/meta-frameworks are not able to reliably
8
- * import the `isolated-vm` package using our `safeDynamicRequire` trick.
9
- *
10
- * The `isolated-vm` import must exist in this separate file, or it will end up
11
- * in the SDK's main entry point, causing errors for users.
12
- */
13
- import ivm from 'isolated-vm';
14
1
  import type { IsolateOptions } from 'isolated-vm';
15
2
  /**
16
3
  * This function initializes the SDK on a Node server. It handles importing the
@@ -21,6 +8,6 @@ import type { IsolateOptions } from 'isolated-vm';
21
8
  * - The NextJS Pages router's `_document.tsx`
22
9
  * - Your Remix route's `loader`
23
10
  */
24
- export declare const initializeNodeRuntime: ({ ivmIsolateOptions }: {
25
- ivmIsolateOptions?: ivm.IsolateOptions | undefined;
11
+ export declare const initializeNodeRuntime: (args?: {
12
+ ivmIsolateOptions?: IsolateOptions;
26
13
  }) => void;
@@ -21,6 +21,7 @@ import { setIvm } from './node-runtime';
21
21
  * - The NextJS Pages router's `_document.tsx`
22
22
  * - Your Remix route's `loader`
23
23
  */
24
- export const initializeNodeRuntime = ({ ivmIsolateOptions }) => {
24
+ export const initializeNodeRuntime = (args) => {
25
+ const { ivmIsolateOptions } = args || {};
25
26
  setIvm(ivm, ivmIsolateOptions);
26
27
  };
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -59,7 +59,7 @@ export const generateContentUrl = (options) => {
59
59
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
60
60
  }
61
61
  if (query) {
62
- const flattened = flatten({
62
+ const flattened = flattenMongoQuery({
63
63
  query
64
64
  });
65
65
  for (const key in flattened) {
@@ -4,3 +4,13 @@
4
4
  * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
5
  */
6
6
  export declare function flatten<T extends Record<string, any>>(object: T, path?: string | null, separator?: string): T;
7
+ /**
8
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
9
+ * $ keys are not flattened and are left as is.
10
+ *
11
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
12
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
13
+ */
14
+ export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
15
+ [key: string]: string;
16
+ };
@@ -17,3 +17,23 @@ export function flatten(object, path = null, separator = '.') {
17
17
  };
18
18
  }, {});
19
19
  }
20
+ /**
21
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
22
+ * $ keys are not flattened and are left as is.
23
+ *
24
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
25
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
26
+ */
27
+ export function flattenMongoQuery(obj, _current, _res = {}) {
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ const newKey = _current ? _current + '.' + key : key;
31
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
32
+ flattenMongoQuery(value, newKey, _res);
33
+ }
34
+ else {
35
+ _res[newKey] = value;
36
+ }
37
+ }
38
+ return _res;
39
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "1.0.25",
4
+ "version": "1.0.27",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.25"
1
+ export const SDK_VERSION = "1.0.27"
@@ -23,10 +23,11 @@ import type { IsolateOptions } from 'isolated-vm';
23
23
  * - The NextJS Pages router's `_document.tsx`
24
24
  * - Your Remix route's `loader`
25
25
  */
26
- export const initializeNodeRuntime = ({
27
- ivmIsolateOptions
28
- }: {
26
+ export const initializeNodeRuntime = (args?: {
29
27
  ivmIsolateOptions?: IsolateOptions;
30
28
  }) => {
29
+ const {
30
+ ivmIsolateOptions
31
+ } = args || {};
31
32
  setIvm(ivm, ivmIsolateOptions);
32
33
  }
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -77,11 +77,11 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
77
77
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
78
78
  }
79
79
  if (query) {
80
- const flattened = flatten({
80
+ const flattened = flattenMongoQuery({
81
81
  query
82
82
  });
83
83
  for (const key in flattened) {
84
- url.searchParams.set(key, JSON.stringify((flattened as any)[key]));
84
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
85
85
  }
86
86
  }
87
87
  return url;
@@ -16,4 +16,26 @@ export function flatten<T extends Record<string, any>>(object: T, path: string |
16
16
  [newPath]: value
17
17
  };
18
18
  }, ({} as T));
19
+ }
20
+
21
+ /**
22
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
23
+ * $ keys are not flattened and are left as is.
24
+ *
25
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
26
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
27
+ */
28
+ export function flattenMongoQuery(obj: any, _current?: any, _res: any = {}): {
29
+ [key: string]: string;
30
+ } {
31
+ for (const key in obj) {
32
+ const value = obj[key];
33
+ const newKey = _current ? _current + '.' + key : key;
34
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
35
+ flattenMongoQuery(value, newKey, _res);
36
+ } else {
37
+ _res[newKey] = value;
38
+ }
39
+ }
40
+ return _res;
19
41
  }