@builder.io/sdk-qwik 0.7.1-3 → 0.7.1-5

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.
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const qwik = require("@builder.io/qwik");
4
4
  const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
5
+ const nodeEvaluate = require("./node-evaluate-fc9f27d1.cjs");
6
+ const build = require("@builder.io/qwik/build");
7
+ require("node:module");
5
8
  const Button = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
6
9
  qwik.useStylesScopedQrl(/* @__PURE__ */ qwik.inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
7
10
  return /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
@@ -120,6 +123,127 @@ const getFunctionArguments = ({ builder, context, event, state }) => {
120
123
  event
121
124
  });
122
125
  };
126
+ const getBuilderGlobals = () => ({
127
+ isEditing: isEditing(),
128
+ isBrowser: isBrowser(),
129
+ isServer: !isBrowser(),
130
+ getUserAttributes: () => getUserAttributes()
131
+ });
132
+ const parseCode = (code, { isExpression = true }) => {
133
+ const useReturn = (
134
+ // we disable this for cases where we definitely don't want a return
135
+ isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
136
+ );
137
+ const useCode = useReturn ? `return (${code});` : code;
138
+ return useCode;
139
+ };
140
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
141
+ const set = (obj, _path, value) => {
142
+ if (Object(obj) !== obj)
143
+ return obj;
144
+ const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
145
+ path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
146
+ return obj;
147
+ };
148
+ const ivm = nodeEvaluate.safeDynamicRequire("isolated-vm");
149
+ const getSyncValName = (key) => `bldr_${key}_sync`;
150
+ const BUILDER_SET_STATE_NAME = "BUILDER_SET_STATE";
151
+ const INJECTED_IVM_GLOBAL = "BUILDER_IVM";
152
+ const REF_TO_PROXY_FN = `
153
+ var refToProxy = (obj) => {
154
+ if (typeof obj !== 'object' || obj === null) {
155
+ return obj;
156
+ }
157
+ return new Proxy({}, {
158
+ get(target, key) {
159
+ if (key === 'copySync') {
160
+ return () => obj.copySync();
161
+ }
162
+ const val = obj.getSync(key);
163
+ if (typeof val?.getSync === 'function') {
164
+ return refToProxy(val);
165
+ }
166
+ return val;
167
+ },
168
+ set(target, key, value) {
169
+ const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
170
+ obj.setSync(key, v);
171
+ ${BUILDER_SET_STATE_NAME}(key, value)
172
+ },
173
+ deleteProperty(target, key) {
174
+ obj.deleteSync(key);
175
+ }
176
+ })
177
+ }
178
+ `;
179
+ const processCode = ({ code, args }) => {
180
+ const fnArgs = args.map(([name]) => `var ${name} = refToProxy(${getSyncValName(name)}); `).join("");
181
+ return `
182
+ ${REF_TO_PROXY_FN}
183
+ ${fnArgs}
184
+ function theFunction() {
185
+ ${code}
186
+ }
187
+
188
+ let output = theFunction()
189
+
190
+ if (typeof output === 'object' && output !== null) {
191
+ output = JSON.stringify(output.copySync ? output.copySync() : output);
192
+ }
193
+
194
+ output;
195
+ `;
196
+ };
197
+ const getIsolateContext = () => {
198
+ const isolate = new ivm.Isolate({
199
+ memoryLimit: 128
200
+ });
201
+ return isolate.createContextSync();
202
+ };
203
+ const runInNode = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
204
+ const state = fastClone({
205
+ ...rootState,
206
+ ...localState
207
+ });
208
+ const args = getFunctionArguments({
209
+ builder,
210
+ context,
211
+ event,
212
+ state
213
+ });
214
+ const isolateContext = getIsolateContext();
215
+ const jail = isolateContext.global;
216
+ jail.setSync("global", jail.derefInto());
217
+ jail.setSync("log", function(...logArgs) {
218
+ console.log(...logArgs);
219
+ });
220
+ jail.setSync(BUILDER_SET_STATE_NAME, function(key, value) {
221
+ set(rootState, key, value);
222
+ rootSetState == null ? void 0 : rootSetState(rootState);
223
+ });
224
+ args.forEach(([key, arg]) => {
225
+ const val = typeof arg === "object" ? new ivm.Reference(
226
+ // workaround: methods with default values for arguments is not being cloned over
227
+ key === "builder" ? {
228
+ ...arg,
229
+ getUserAttributes: () => arg.getUserAttributes()
230
+ } : arg
231
+ ) : null;
232
+ jail.setSync(getSyncValName(key), val);
233
+ });
234
+ jail.setSync(INJECTED_IVM_GLOBAL, ivm);
235
+ const evalStr = processCode({
236
+ code,
237
+ args
238
+ });
239
+ const resultStr = isolateContext.evalSync(evalStr);
240
+ try {
241
+ const res = JSON.parse(resultStr);
242
+ return res;
243
+ } catch (_error) {
244
+ return resultStr;
245
+ }
246
+ };
123
247
  const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
124
248
  const functionArgs = getFunctionArguments({
125
249
  builder,
@@ -147,25 +271,17 @@ function flattenState(rootState, localState, rootSetState) {
147
271
  }
148
272
  });
149
273
  }
274
+ const chooseBrowserOrServerEval = (args) => !build.isServer ? runInBrowser(args) : runInNode(args);
150
275
  function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
151
276
  if (code === "") {
152
277
  logger.warn("Skipping evaluation of empty code block.");
153
278
  return;
154
279
  }
155
- const builder = {
156
- isEditing: isEditing(),
157
- isBrowser: isBrowser(),
158
- isServer: !isBrowser(),
159
- getUserAttributes: () => getUserAttributes()
160
- };
161
- const useReturn = (
162
- // we disable this for cases where we definitely don't want a return
163
- isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
164
- );
165
- const useCode = useReturn ? `return (${code});` : code;
166
280
  const args = {
167
- code: useCode,
168
- builder,
281
+ code: parseCode(code, {
282
+ isExpression
283
+ }),
284
+ builder: getBuilderGlobals(),
169
285
  context,
170
286
  event,
171
287
  rootSetState,
@@ -173,7 +289,7 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
173
289
  localState
174
290
  };
175
291
  try {
176
- return runInBrowser(args);
292
+ return chooseBrowserOrServerEval(args);
177
293
  } catch (e) {
178
294
  logger.error("Failed code evaluation: " + e.message, {
179
295
  code
@@ -181,14 +297,6 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
181
297
  return void 0;
182
298
  }
183
299
  }
184
- const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
185
- const set = (obj, _path, value) => {
186
- if (Object(obj) !== obj)
187
- return obj;
188
- const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
189
- path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
190
- return obj;
191
- };
192
300
  function transformBlock(block) {
193
301
  return block;
194
302
  }
@@ -2809,9 +2917,10 @@ const getBuilderSearchParamsFromWindow = () => {
2809
2917
  };
2810
2918
  const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2811
2919
  const DEFAULT_API_VERSION = "v3";
2920
+ const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
2812
2921
  const generateContentUrl = (options) => {
2813
2922
  let { noTraverse = false } = options;
2814
- const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
2923
+ const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
2815
2924
  if (!apiKey)
2816
2925
  throw new Error("Missing API key");
2817
2926
  if (![
@@ -2822,6 +2931,24 @@ const generateContentUrl = (options) => {
2822
2931
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
2823
2932
  noTraverse = true;
2824
2933
  const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
2934
+ url.searchParams.set("omit", omit || "meta.componentsUsed");
2935
+ if (fields)
2936
+ url.searchParams.set("fields", fields);
2937
+ if (Number.isFinite(offset) && offset > -1)
2938
+ url.searchParams.set("offset", String(Math.floor(offset)));
2939
+ if (typeof includeUnpublished === "boolean")
2940
+ url.searchParams.set("includeUnpublished", String(includeUnpublished));
2941
+ if (cacheSeconds && isPositiveNumber(cacheSeconds))
2942
+ url.searchParams.set("cacheSeconds", String(cacheSeconds));
2943
+ if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds))
2944
+ url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
2945
+ if (sort) {
2946
+ const flattened2 = flatten({
2947
+ sort
2948
+ });
2949
+ for (const key in flattened2)
2950
+ url.searchParams.set(key, JSON.stringify(flattened2[key]));
2951
+ }
2825
2952
  const queryOptions = {
2826
2953
  ...getBuilderSearchParamsFromWindow(),
2827
2954
  ...normalizeSearchParams(options.options || {})
@@ -3095,7 +3222,7 @@ const getInteractionPropertiesForEvent = (event) => {
3095
3222
  }
3096
3223
  };
3097
3224
  };
3098
- const SDK_VERSION = "0.7.1-3";
3225
+ const SDK_VERSION = "0.7.1-4";
3099
3226
  const registry = {};
3100
3227
  function register(type, info) {
3101
3228
  let typeList = registry[type];
@@ -1,5 +1,8 @@
1
1
  import { componentQrl, inlinedQrl, useStylesScopedQrl, _jsxC, _jsxS, _fnSignal, createContextId, _jsxQ, _jsxBranch, useComputedQrl, useLexicalScope, _IMMUTABLE, Slot, useStore, useContextProvider, _wrapProp, useContext, createElement, Fragment as Fragment$1, useSignal, useTaskQrl, useOn } from "@builder.io/qwik";
2
2
  import { Fragment } from "@builder.io/qwik/jsx-runtime";
3
+ import { s as safeDynamicRequire } from "./node-evaluate-15fe5e77.js";
4
+ import { isServer } from "@builder.io/qwik/build";
5
+ import "node:module";
3
6
  const Button = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
4
7
  useStylesScopedQrl(/* @__PURE__ */ inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
5
8
  return /* @__PURE__ */ _jsxC(Fragment, {
@@ -118,6 +121,127 @@ const getFunctionArguments = ({ builder, context, event, state }) => {
118
121
  event
119
122
  });
120
123
  };
124
+ const getBuilderGlobals = () => ({
125
+ isEditing: isEditing(),
126
+ isBrowser: isBrowser(),
127
+ isServer: !isBrowser(),
128
+ getUserAttributes: () => getUserAttributes()
129
+ });
130
+ const parseCode = (code, { isExpression = true }) => {
131
+ const useReturn = (
132
+ // we disable this for cases where we definitely don't want a return
133
+ isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
134
+ );
135
+ const useCode = useReturn ? `return (${code});` : code;
136
+ return useCode;
137
+ };
138
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
139
+ const set = (obj, _path, value) => {
140
+ if (Object(obj) !== obj)
141
+ return obj;
142
+ const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
143
+ path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
144
+ return obj;
145
+ };
146
+ const ivm = safeDynamicRequire("isolated-vm");
147
+ const getSyncValName = (key) => `bldr_${key}_sync`;
148
+ const BUILDER_SET_STATE_NAME = "BUILDER_SET_STATE";
149
+ const INJECTED_IVM_GLOBAL = "BUILDER_IVM";
150
+ const REF_TO_PROXY_FN = `
151
+ var refToProxy = (obj) => {
152
+ if (typeof obj !== 'object' || obj === null) {
153
+ return obj;
154
+ }
155
+ return new Proxy({}, {
156
+ get(target, key) {
157
+ if (key === 'copySync') {
158
+ return () => obj.copySync();
159
+ }
160
+ const val = obj.getSync(key);
161
+ if (typeof val?.getSync === 'function') {
162
+ return refToProxy(val);
163
+ }
164
+ return val;
165
+ },
166
+ set(target, key, value) {
167
+ const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
168
+ obj.setSync(key, v);
169
+ ${BUILDER_SET_STATE_NAME}(key, value)
170
+ },
171
+ deleteProperty(target, key) {
172
+ obj.deleteSync(key);
173
+ }
174
+ })
175
+ }
176
+ `;
177
+ const processCode = ({ code, args }) => {
178
+ const fnArgs = args.map(([name]) => `var ${name} = refToProxy(${getSyncValName(name)}); `).join("");
179
+ return `
180
+ ${REF_TO_PROXY_FN}
181
+ ${fnArgs}
182
+ function theFunction() {
183
+ ${code}
184
+ }
185
+
186
+ let output = theFunction()
187
+
188
+ if (typeof output === 'object' && output !== null) {
189
+ output = JSON.stringify(output.copySync ? output.copySync() : output);
190
+ }
191
+
192
+ output;
193
+ `;
194
+ };
195
+ const getIsolateContext = () => {
196
+ const isolate = new ivm.Isolate({
197
+ memoryLimit: 128
198
+ });
199
+ return isolate.createContextSync();
200
+ };
201
+ const runInNode = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
202
+ const state = fastClone({
203
+ ...rootState,
204
+ ...localState
205
+ });
206
+ const args = getFunctionArguments({
207
+ builder,
208
+ context,
209
+ event,
210
+ state
211
+ });
212
+ const isolateContext = getIsolateContext();
213
+ const jail = isolateContext.global;
214
+ jail.setSync("global", jail.derefInto());
215
+ jail.setSync("log", function(...logArgs) {
216
+ console.log(...logArgs);
217
+ });
218
+ jail.setSync(BUILDER_SET_STATE_NAME, function(key, value) {
219
+ set(rootState, key, value);
220
+ rootSetState == null ? void 0 : rootSetState(rootState);
221
+ });
222
+ args.forEach(([key, arg]) => {
223
+ const val = typeof arg === "object" ? new ivm.Reference(
224
+ // workaround: methods with default values for arguments is not being cloned over
225
+ key === "builder" ? {
226
+ ...arg,
227
+ getUserAttributes: () => arg.getUserAttributes()
228
+ } : arg
229
+ ) : null;
230
+ jail.setSync(getSyncValName(key), val);
231
+ });
232
+ jail.setSync(INJECTED_IVM_GLOBAL, ivm);
233
+ const evalStr = processCode({
234
+ code,
235
+ args
236
+ });
237
+ const resultStr = isolateContext.evalSync(evalStr);
238
+ try {
239
+ const res = JSON.parse(resultStr);
240
+ return res;
241
+ } catch (_error) {
242
+ return resultStr;
243
+ }
244
+ };
121
245
  const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
122
246
  const functionArgs = getFunctionArguments({
123
247
  builder,
@@ -145,25 +269,17 @@ function flattenState(rootState, localState, rootSetState) {
145
269
  }
146
270
  });
147
271
  }
272
+ const chooseBrowserOrServerEval = (args) => !isServer ? runInBrowser(args) : runInNode(args);
148
273
  function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
149
274
  if (code === "") {
150
275
  logger.warn("Skipping evaluation of empty code block.");
151
276
  return;
152
277
  }
153
- const builder = {
154
- isEditing: isEditing(),
155
- isBrowser: isBrowser(),
156
- isServer: !isBrowser(),
157
- getUserAttributes: () => getUserAttributes()
158
- };
159
- const useReturn = (
160
- // we disable this for cases where we definitely don't want a return
161
- isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
162
- );
163
- const useCode = useReturn ? `return (${code});` : code;
164
278
  const args = {
165
- code: useCode,
166
- builder,
279
+ code: parseCode(code, {
280
+ isExpression
281
+ }),
282
+ builder: getBuilderGlobals(),
167
283
  context,
168
284
  event,
169
285
  rootSetState,
@@ -171,7 +287,7 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
171
287
  localState
172
288
  };
173
289
  try {
174
- return runInBrowser(args);
290
+ return chooseBrowserOrServerEval(args);
175
291
  } catch (e) {
176
292
  logger.error("Failed code evaluation: " + e.message, {
177
293
  code
@@ -179,14 +295,6 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
179
295
  return void 0;
180
296
  }
181
297
  }
182
- const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
183
- const set = (obj, _path, value) => {
184
- if (Object(obj) !== obj)
185
- return obj;
186
- const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
187
- path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
188
- return obj;
189
- };
190
298
  function transformBlock(block) {
191
299
  return block;
192
300
  }
@@ -2807,9 +2915,10 @@ const getBuilderSearchParamsFromWindow = () => {
2807
2915
  };
2808
2916
  const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2809
2917
  const DEFAULT_API_VERSION = "v3";
2918
+ const isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
2810
2919
  const generateContentUrl = (options) => {
2811
2920
  let { noTraverse = false } = options;
2812
- const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
2921
+ const { limit = 30, userAttributes, query, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
2813
2922
  if (!apiKey)
2814
2923
  throw new Error("Missing API key");
2815
2924
  if (![
@@ -2820,6 +2929,24 @@ const generateContentUrl = (options) => {
2820
2929
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options))
2821
2930
  noTraverse = true;
2822
2931
  const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
2932
+ url.searchParams.set("omit", omit || "meta.componentsUsed");
2933
+ if (fields)
2934
+ url.searchParams.set("fields", fields);
2935
+ if (Number.isFinite(offset) && offset > -1)
2936
+ url.searchParams.set("offset", String(Math.floor(offset)));
2937
+ if (typeof includeUnpublished === "boolean")
2938
+ url.searchParams.set("includeUnpublished", String(includeUnpublished));
2939
+ if (cacheSeconds && isPositiveNumber(cacheSeconds))
2940
+ url.searchParams.set("cacheSeconds", String(cacheSeconds));
2941
+ if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds))
2942
+ url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
2943
+ if (sort) {
2944
+ const flattened2 = flatten({
2945
+ sort
2946
+ });
2947
+ for (const key in flattened2)
2948
+ url.searchParams.set(key, JSON.stringify(flattened2[key]));
2949
+ }
2823
2950
  const queryOptions = {
2824
2951
  ...getBuilderSearchParamsFromWindow(),
2825
2952
  ...normalizeSearchParams(options.options || {})
@@ -3093,7 +3220,7 @@ const getInteractionPropertiesForEvent = (event) => {
3093
3220
  }
3094
3221
  };
3095
3222
  };
3096
- const SDK_VERSION = "0.7.1-3";
3223
+ const SDK_VERSION = "0.7.1-4";
3097
3224
  const registry = {};
3098
3225
  function register(type, info) {
3099
3226
  let typeList = registry[type];
@@ -0,0 +1,10 @@
1
+ import { createRequire } from "node:module";
2
+ const noop = () => null;
3
+ let safeDynamicRequire = noop;
4
+ try {
5
+ safeDynamicRequire = createRequire(import.meta.url);
6
+ } catch (error) {
7
+ }
8
+ export {
9
+ safeDynamicRequire as s
10
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ const node_module = require("node:module");
3
+ const noop = () => null;
4
+ exports.safeDynamicRequire = noop;
5
+ try {
6
+ exports.safeDynamicRequire = node_module.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : document.currentScript && document.currentScript.src || new URL("node-evaluate-fc9f27d1.cjs", document.baseURI).href);
7
+ } catch (error) {
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.7.1-3",
3
+ "version": "0.7.1-5",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/edge/index.qwik.cjs",
@@ -109,6 +109,7 @@
109
109
  },
110
110
  "peerDependencies": {
111
111
  "@builder.io/qwik": ">=1.0.0",
112
+ "isolated-vm": "^4.6.0",
112
113
  "undici": "^5.14.0"
113
114
  },
114
115
  "nx": {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.7.1-3";
1
+ export declare const SDK_VERSION = "0.7.1-4";
@@ -0,0 +1,6 @@
1
+ import type { ExecutorArgs } from './helpers.js';
2
+ /**
3
+ * Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
4
+ * end up sending the server runtime code to the browser (most notably in dev mode).
5
+ */
6
+ export declare const chooseBrowserOrServerEval: (args: ExecutorArgs) => any;
@@ -1,6 +1,2 @@
1
- import type { ExecutorArgs } from './helpers.js';
2
- export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
3
- event?: Event;
4
- isExpression?: boolean;
5
- };
1
+ import type { EvaluatorArgs } from './helpers.js';
6
2
  export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: EvaluatorArgs): any;
@@ -1,5 +1,9 @@
1
1
  import type { BuilderContextInterface, BuilderRenderState } from '../../context/types.js';
2
- import type { getUserAttributes } from '../track/helpers.js';
2
+ import { getUserAttributes } from '../track/helpers.js';
3
+ export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
4
+ event?: Event;
5
+ isExpression?: boolean;
6
+ };
3
7
  export type BuilderGlobals = {
4
8
  isEditing: boolean | undefined;
5
9
  isBrowser: boolean | undefined;
@@ -16,3 +20,5 @@ export type FunctionArguments = ReturnType<typeof getFunctionArguments>;
16
20
  export declare const getFunctionArguments: ({ builder, context, event, state }: Pick<ExecutorArgs, "context" | "builder" | "event"> & {
17
21
  state: BuilderRenderState;
18
22
  }) => [string, Event | BuilderRenderState | import("../../context/types.js").BuilderRenderContext | BuilderGlobals | undefined][];
23
+ export declare const getBuilderGlobals: () => BuilderGlobals;
24
+ export declare const parseCode: (code: string, { isExpression }: Pick<EvaluatorArgs, 'isExpression'>) => string;
@@ -1 +1 @@
1
- export { evaluator } from '../browser-runtime/index.js';
1
+ export { runInNode as evaluator } from './node-runtime.js';
@@ -1,2 +1,2 @@
1
1
  import type { ExecutorArgs } from '../helpers.js';
2
- export declare const evaluator: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
2
+ export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * We use the less hacky, but more modern `createRequire` API for Qwik. That's because the `eval('require')` trick does
3
+ * not work with Qwik.
4
+ */
5
+ /// <reference types="node" />
6
+ /// <reference types="react-native" />
7
+ export declare let safeDynamicRequire: typeof require;
@@ -5,11 +5,42 @@ export interface GetContentOptions {
5
5
  apiKey: string;
6
6
  /** Number of items to fetch. Default is 1 */
7
7
  limit?: number;
8
- /** User attributes to target on, such as { urlPath: '/foo', device: 'mobile', ...etc } */
8
+ /**
9
+ * Use to specify an offset for pagination of results. The default is 0.
10
+ */
11
+ offset?: number;
12
+ /**
13
+ * User attribute key value pairs to be used for targeting
14
+ * https://www.builder.io/c/docs/custom-targeting-attributes
15
+ *
16
+ * e.g.
17
+ * ```js
18
+ * userAttributes: {
19
+ * urlPath: '/',
20
+ * returnVisitor: true,
21
+ * device: 'mobile'
22
+ * }
23
+ * ```
24
+ */
9
25
  userAttributes?: (Record<string, string> & {
10
26
  urlPath?: string;
11
27
  }) | null;
12
- /** Custom query */
28
+ /**
29
+ * Mongodb style query of your data. E.g.:
30
+ *
31
+ * ```js
32
+ * query: {
33
+ * id: 'abc123',
34
+ * data: {
35
+ * myCustomField: { $gt: 20 },
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * See more info on MongoDB's query operators and format.
41
+ *
42
+ * @see {@link https://docs.mongodb.com/manual/reference/operator/query/}
43
+ */
13
44
  query?: Record<string, any>;
14
45
  /**
15
46
  * Any other API options.
@@ -30,7 +61,7 @@ export interface GetContentOptions {
30
61
  */
31
62
  canTrack?: boolean;
32
63
  /**
33
- * Include references in the response. Defaults to `true`.
64
+ * Include content of references in the response. Defaults to `true`.
34
65
  * @deprecated use `enrich` instead
35
66
  */
36
67
  includeRefs?: boolean;
@@ -48,4 +79,64 @@ export interface GetContentOptions {
48
79
  * Defaults to `v3`.
49
80
  */
50
81
  apiVersion?: 'v2' | 'v3';
82
+ /**
83
+ * Only include these fields.
84
+ * Note: 'omit' takes precedence over 'fields'
85
+ *
86
+ * @example
87
+ * ```
88
+ * fields: 'id, name, data.customField'
89
+ * ```
90
+ */
91
+ fields?: string;
92
+ /**
93
+ * Omit only these fields.
94
+ * Note: 'omit' takes precedence over 'fields'
95
+ *
96
+ * @example
97
+ * ```
98
+ * omit: 'data.bigField,data.blocks'
99
+ * ```
100
+ */
101
+ omit?: string;
102
+ /**
103
+ * Seconds to cache content. Sets the max-age of the cache-control header
104
+ * response header.
105
+ *
106
+ * Use a higher value for better performance, lower for content that will change more frequently
107
+ *
108
+ * @see {@link https://www.builder.io/c/docs/query-api#__next:~:text=%26includeRefs%3Dtrue-,cacheSeconds,-No}
109
+ */
110
+ cacheSeconds?: number;
111
+ /**
112
+ * Builder.io uses stale-while-revalidate caching at the CDN level. This means we always serve
113
+ * from edge cache and update caches in the background for maximum possible performance. This also
114
+ * means that the more frequently content is requested, the more fresh it will be. The longest we
115
+ * will ever hold something in stale cache is 1 day by default, and you can set this to be shorter
116
+ * yourself as well. We suggest keeping this high unless you have content that must change rapidly
117
+ * and gets very little traffic.
118
+ *
119
+ * @see {@link https://www.fastly.com/blog/prevent-application-network-instability-serve-stale-content}
120
+ */
121
+ staleCacheSeconds?: number;
122
+ /**
123
+ * Property to order results by.
124
+ * Use 1 for ascending and -1 for descending.
125
+ *
126
+ * The key is what you're sorting on, so the following example sorts by createdDate
127
+ * and because the value is 1, the sort is ascending.
128
+ *
129
+ * @example
130
+ * ```
131
+ * createdDate: 1
132
+ * ```
133
+ */
134
+ sort?: {
135
+ [key: string]: 1 | -1;
136
+ };
137
+ /**
138
+ * Include content entries in a response that are still in
139
+ * draft mode and un-archived. Default is false.
140
+ */
141
+ includeUnpublished?: boolean;
51
142
  }