@builder.io/sdk-qwik 0.0.38 → 0.1.1

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.
package/README.md CHANGED
@@ -9,6 +9,10 @@ Installing the Qwik SDK is done in two steps:
9
9
  1. Set up Qwik-city project.
10
10
  2. Install the Qwik SDK into your Qwik-city project.
11
11
 
12
+ ### Fetch
13
+
14
+ This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
15
+
12
16
  ### Set up Qwik-city project
13
17
 
14
18
  1. Follow the instructions on [Qwik-city](https://qwik.builder.io/qwikcity/overview)
@@ -2168,73 +2168,24 @@ const componentInfo = {
2168
2168
  }
2169
2169
  ];
2170
2170
 
2171
- /**
2172
- * Convert deep object to a flat object with dots
2173
- *
2174
- * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
2175
- */ function flatten(object, path = null, separator = '.') {
2176
- return Object.keys(object).reduce((acc, key)=>{
2177
- const value = object[key];
2178
- const newPath = [
2179
- path,
2180
- key
2181
- ].filter(Boolean).join(separator);
2182
- const isObject = [
2183
- typeof value === 'object',
2184
- value !== null,
2185
- !(Array.isArray(value) && value.length === 0)
2186
- ].every(Boolean);
2187
- return isObject ? {
2188
- ...acc,
2189
- ...flatten(value, newPath, separator)
2190
- } : {
2191
- ...acc,
2192
- [newPath]: value
2193
- };
2194
- }, {});
2195
- }
2196
-
2197
- const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
2198
- const BUILDER_OPTIONS_PREFIX = 'options.';
2199
- const convertSearchParamsToQueryObject = (searchParams)=>{
2200
- const options = {};
2201
- searchParams.forEach((value, key)=>{
2202
- options[key] = value;
2203
- });
2204
- return options;
2205
- };
2206
- const getBuilderSearchParams = (_options)=>{
2207
- if (!_options) return {};
2208
- const options = normalizeSearchParams(_options);
2209
- const newOptions = {};
2210
- Object.keys(options).forEach((key)=>{
2211
- if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
2212
- const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
2213
- newOptions[trimmedKey] = options[key];
2214
- }
2215
- });
2216
- return newOptions;
2217
- };
2218
- const getBuilderSearchParamsFromWindow = ()=>{
2219
- if (!isBrowser()) return {};
2220
- const searchParams = new URLSearchParams(window.location.search);
2221
- return getBuilderSearchParams(searchParams);
2222
- };
2223
- const normalizeSearchParams = (searchParams)=>searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2224
-
2225
2171
  function getGlobalThis() {
2226
2172
  if (typeof globalThis !== 'undefined') return globalThis;
2227
2173
  if (typeof window !== 'undefined') return window;
2228
2174
  if (typeof global !== 'undefined') return global;
2229
2175
  if (typeof self !== 'undefined') return self;
2230
- return null;
2176
+ return globalThis;
2231
2177
  }
2232
2178
 
2233
- async function getFetch() {
2179
+ function getFetch() {
2234
2180
  const globalFetch = getGlobalThis().fetch;
2235
- if (typeof globalFetch === 'undefined' && typeof global !== 'undefined') throw new Error('`fetch()` not found, ensure you have it as part of your polyfills.');
2236
- return globalFetch.default || globalFetch;
2181
+ if (typeof globalFetch === 'undefined') {
2182
+ console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
2183
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
2184
+ throw new Error('Builder SDK could not find a global `fetch` function');
2185
+ }
2186
+ return globalFetch;
2237
2187
  }
2188
+ const fetch$1 = getFetch();
2238
2189
 
2239
2190
  /**
2240
2191
  * Only gets one level up from hostname
@@ -2401,12 +2352,60 @@ const handleABTesting = async ({ item , canTrack })=>{
2401
2352
  Object.assign(item, variationValue);
2402
2353
  };
2403
2354
 
2404
- async function getContent(options) {
2405
- return (await getAllContent({
2406
- ...options,
2407
- limit: 1
2408
- })).results[0] || null;
2355
+ /**
2356
+ * Convert deep object to a flat object with dots
2357
+ *
2358
+ * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
2359
+ */ function flatten(object, path = null, separator = '.') {
2360
+ return Object.keys(object).reduce((acc, key)=>{
2361
+ const value = object[key];
2362
+ const newPath = [
2363
+ path,
2364
+ key
2365
+ ].filter(Boolean).join(separator);
2366
+ const isObject = [
2367
+ typeof value === 'object',
2368
+ value !== null,
2369
+ !(Array.isArray(value) && value.length === 0)
2370
+ ].every(Boolean);
2371
+ return isObject ? {
2372
+ ...acc,
2373
+ ...flatten(value, newPath, separator)
2374
+ } : {
2375
+ ...acc,
2376
+ [newPath]: value
2377
+ };
2378
+ }, {});
2409
2379
  }
2380
+
2381
+ const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
2382
+ const BUILDER_OPTIONS_PREFIX = 'options.';
2383
+ const convertSearchParamsToQueryObject = (searchParams)=>{
2384
+ const options = {};
2385
+ searchParams.forEach((value, key)=>{
2386
+ options[key] = value;
2387
+ });
2388
+ return options;
2389
+ };
2390
+ const getBuilderSearchParams = (_options)=>{
2391
+ if (!_options) return {};
2392
+ const options = normalizeSearchParams(_options);
2393
+ const newOptions = {};
2394
+ Object.keys(options).forEach((key)=>{
2395
+ if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
2396
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
2397
+ newOptions[trimmedKey] = options[key];
2398
+ }
2399
+ });
2400
+ return newOptions;
2401
+ };
2402
+ const getBuilderSearchParamsFromWindow = ()=>{
2403
+ if (!isBrowser()) return {};
2404
+ const searchParams = new URLSearchParams(window.location.search);
2405
+ return getBuilderSearchParams(searchParams);
2406
+ };
2407
+ const normalizeSearchParams = (searchParams)=>searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2408
+
2410
2409
  const generateContentUrl = (options)=>{
2411
2410
  const { limit =30 , userAttributes , query , noTraverse =false , model , apiKey , includeRefs =true , locale , } = options;
2412
2411
  if (!apiKey) throw new Error('Missing API key');
@@ -2426,10 +2425,17 @@ const generateContentUrl = (options)=>{
2426
2425
  }
2427
2426
  return url;
2428
2427
  };
2428
+
2429
+ async function getContent(options) {
2430
+ return (await getAllContent({
2431
+ ...options,
2432
+ limit: 1
2433
+ })).results[0] || null;
2434
+ }
2429
2435
  async function getAllContent(options) {
2430
2436
  const url = generateContentUrl(options);
2431
- const fetch = await getFetch();
2432
- const content = await fetch(url.href).then((res)=>res.json());
2437
+ const res = await fetch$1(url.href);
2438
+ const content = await res.json();
2433
2439
  const canTrack = options.canTrack !== false;
2434
2440
  if (canTrack && // This makes sure we have a non-error response with the results array.
2435
2441
  Array.isArray(content.results)) for (const item of content.results)await handleABTesting({
@@ -2767,7 +2773,7 @@ const evalExpression = function evalExpression(props, state, elementRef, express
2767
2773
  }));
2768
2774
  };
2769
2775
  const handleRequest = function handleRequest(props, state, elementRef, { url , key }) {
2770
- getFetch().then((fetch)=>fetch(url)).then((response)=>response.json()).then((json)=>{
2776
+ fetch$1(url).then((response)=>response.json()).then((json)=>{
2771
2777
  const newOverrideState = {
2772
2778
  ...state.overrideState,
2773
2779
  [key]: json
@@ -3052,7 +3058,6 @@ exports.Video = Video$1;
3052
3058
  exports.components = components;
3053
3059
  exports.convertSearchParamsToQueryObject = convertSearchParamsToQueryObject;
3054
3060
  exports.createRegisterComponentMessage = createRegisterComponentMessage;
3055
- exports.generateContentUrl = generateContentUrl;
3056
3061
  exports.getAllContent = getAllContent;
3057
3062
  exports.getBuilderSearchParams = getBuilderSearchParams;
3058
3063
  exports.getBuilderSearchParamsFromWindow = getBuilderSearchParamsFromWindow;
@@ -2164,73 +2164,24 @@ const componentInfo = {
2164
2164
  }
2165
2165
  ];
2166
2166
 
2167
- /**
2168
- * Convert deep object to a flat object with dots
2169
- *
2170
- * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
2171
- */ function flatten(object, path = null, separator = '.') {
2172
- return Object.keys(object).reduce((acc, key)=>{
2173
- const value = object[key];
2174
- const newPath = [
2175
- path,
2176
- key
2177
- ].filter(Boolean).join(separator);
2178
- const isObject = [
2179
- typeof value === 'object',
2180
- value !== null,
2181
- !(Array.isArray(value) && value.length === 0)
2182
- ].every(Boolean);
2183
- return isObject ? {
2184
- ...acc,
2185
- ...flatten(value, newPath, separator)
2186
- } : {
2187
- ...acc,
2188
- [newPath]: value
2189
- };
2190
- }, {});
2191
- }
2192
-
2193
- const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
2194
- const BUILDER_OPTIONS_PREFIX = 'options.';
2195
- const convertSearchParamsToQueryObject = (searchParams)=>{
2196
- const options = {};
2197
- searchParams.forEach((value, key)=>{
2198
- options[key] = value;
2199
- });
2200
- return options;
2201
- };
2202
- const getBuilderSearchParams = (_options)=>{
2203
- if (!_options) return {};
2204
- const options = normalizeSearchParams(_options);
2205
- const newOptions = {};
2206
- Object.keys(options).forEach((key)=>{
2207
- if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
2208
- const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
2209
- newOptions[trimmedKey] = options[key];
2210
- }
2211
- });
2212
- return newOptions;
2213
- };
2214
- const getBuilderSearchParamsFromWindow = ()=>{
2215
- if (!isBrowser()) return {};
2216
- const searchParams = new URLSearchParams(window.location.search);
2217
- return getBuilderSearchParams(searchParams);
2218
- };
2219
- const normalizeSearchParams = (searchParams)=>searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2220
-
2221
2167
  function getGlobalThis() {
2222
2168
  if (typeof globalThis !== 'undefined') return globalThis;
2223
2169
  if (typeof window !== 'undefined') return window;
2224
2170
  if (typeof global !== 'undefined') return global;
2225
2171
  if (typeof self !== 'undefined') return self;
2226
- return null;
2172
+ return globalThis;
2227
2173
  }
2228
2174
 
2229
- async function getFetch() {
2175
+ function getFetch() {
2230
2176
  const globalFetch = getGlobalThis().fetch;
2231
- if (typeof globalFetch === 'undefined' && typeof global !== 'undefined') throw new Error('`fetch()` not found, ensure you have it as part of your polyfills.');
2232
- return globalFetch.default || globalFetch;
2177
+ if (typeof globalFetch === 'undefined') {
2178
+ console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
2179
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
2180
+ throw new Error('Builder SDK could not find a global `fetch` function');
2181
+ }
2182
+ return globalFetch;
2233
2183
  }
2184
+ const fetch$1 = getFetch();
2234
2185
 
2235
2186
  /**
2236
2187
  * Only gets one level up from hostname
@@ -2397,12 +2348,60 @@ const handleABTesting = async ({ item , canTrack })=>{
2397
2348
  Object.assign(item, variationValue);
2398
2349
  };
2399
2350
 
2400
- async function getContent(options) {
2401
- return (await getAllContent({
2402
- ...options,
2403
- limit: 1
2404
- })).results[0] || null;
2351
+ /**
2352
+ * Convert deep object to a flat object with dots
2353
+ *
2354
+ * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
2355
+ */ function flatten(object, path = null, separator = '.') {
2356
+ return Object.keys(object).reduce((acc, key)=>{
2357
+ const value = object[key];
2358
+ const newPath = [
2359
+ path,
2360
+ key
2361
+ ].filter(Boolean).join(separator);
2362
+ const isObject = [
2363
+ typeof value === 'object',
2364
+ value !== null,
2365
+ !(Array.isArray(value) && value.length === 0)
2366
+ ].every(Boolean);
2367
+ return isObject ? {
2368
+ ...acc,
2369
+ ...flatten(value, newPath, separator)
2370
+ } : {
2371
+ ...acc,
2372
+ [newPath]: value
2373
+ };
2374
+ }, {});
2405
2375
  }
2376
+
2377
+ const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
2378
+ const BUILDER_OPTIONS_PREFIX = 'options.';
2379
+ const convertSearchParamsToQueryObject = (searchParams)=>{
2380
+ const options = {};
2381
+ searchParams.forEach((value, key)=>{
2382
+ options[key] = value;
2383
+ });
2384
+ return options;
2385
+ };
2386
+ const getBuilderSearchParams = (_options)=>{
2387
+ if (!_options) return {};
2388
+ const options = normalizeSearchParams(_options);
2389
+ const newOptions = {};
2390
+ Object.keys(options).forEach((key)=>{
2391
+ if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
2392
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
2393
+ newOptions[trimmedKey] = options[key];
2394
+ }
2395
+ });
2396
+ return newOptions;
2397
+ };
2398
+ const getBuilderSearchParamsFromWindow = ()=>{
2399
+ if (!isBrowser()) return {};
2400
+ const searchParams = new URLSearchParams(window.location.search);
2401
+ return getBuilderSearchParams(searchParams);
2402
+ };
2403
+ const normalizeSearchParams = (searchParams)=>searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2404
+
2406
2405
  const generateContentUrl = (options)=>{
2407
2406
  const { limit =30 , userAttributes , query , noTraverse =false , model , apiKey , includeRefs =true , locale , } = options;
2408
2407
  if (!apiKey) throw new Error('Missing API key');
@@ -2422,10 +2421,17 @@ const generateContentUrl = (options)=>{
2422
2421
  }
2423
2422
  return url;
2424
2423
  };
2424
+
2425
+ async function getContent(options) {
2426
+ return (await getAllContent({
2427
+ ...options,
2428
+ limit: 1
2429
+ })).results[0] || null;
2430
+ }
2425
2431
  async function getAllContent(options) {
2426
2432
  const url = generateContentUrl(options);
2427
- const fetch = await getFetch();
2428
- const content = await fetch(url.href).then((res)=>res.json());
2433
+ const res = await fetch$1(url.href);
2434
+ const content = await res.json();
2429
2435
  const canTrack = options.canTrack !== false;
2430
2436
  if (canTrack && // This makes sure we have a non-error response with the results array.
2431
2437
  Array.isArray(content.results)) for (const item of content.results)await handleABTesting({
@@ -2763,7 +2769,7 @@ const evalExpression = function evalExpression(props, state, elementRef, express
2763
2769
  }));
2764
2770
  };
2765
2771
  const handleRequest = function handleRequest(props, state, elementRef, { url , key }) {
2766
- getFetch().then((fetch)=>fetch(url)).then((response)=>response.json()).then((json)=>{
2772
+ fetch$1(url).then((response)=>response.json()).then((json)=>{
2767
2773
  const newOverrideState = {
2768
2774
  ...state.overrideState,
2769
2775
  [key]: json
@@ -3035,4 +3041,4 @@ function setEditorSettings(newSettings) {
3035
3041
  }
3036
3042
  }
3037
3043
 
3038
- export { Button$1 as Button, Columns$1 as Columns, Fragment, Image$1 as Image, RenderBlocks$1 as RenderBlocks, RenderContent$1 as RenderContent, Section, Symbol$2 as Symbol, Text$1 as Text, Video$1 as Video, components, convertSearchParamsToQueryObject, createRegisterComponentMessage, generateContentUrl, getAllContent, getBuilderSearchParams, getBuilderSearchParamsFromWindow, getContent, isEditing, isPreviewing, normalizeSearchParams, register, registerComponent, setEditorSettings, track };
3044
+ export { Button$1 as Button, Columns$1 as Columns, Fragment, Image$1 as Image, RenderBlocks$1 as RenderBlocks, RenderContent$1 as RenderContent, Section, Symbol$2 as Symbol, Text$1 as Text, Video$1 as Video, components, convertSearchParamsToQueryObject, createRegisterComponentMessage, getAllContent, getBuilderSearchParams, getBuilderSearchParamsFromWindow, getContent, isEditing, isPreviewing, normalizeSearchParams, register, registerComponent, setEditorSettings, track };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.0.38",
3
+ "version": "0.1.1",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -23,8 +23,9 @@
23
23
  "scripts": {
24
24
  "typecheck": "tsc --noEmit",
25
25
  "build": "tsc && vite build --mode lib",
26
- "release:patch": "yarn run build && yarn version patch && npm publish --access public",
27
- "release:dev": "yarn run build && npm version prerelease && npm publish --tag latest --access public"
26
+ "release:patch": "yarn run build && npm version patch && npm publish",
27
+ "release:minor": "yarn run build && npm version minor && npm publish",
28
+ "release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/node": "latest",
@@ -0,0 +1,2 @@
1
+ import type { GetContentOptions } from './types.js';
2
+ export declare const generateContentUrl: (options: GetContentOptions) => URL;
@@ -1,7 +1,6 @@
1
1
  import type { BuilderContent } from '../../types/builder-content.js';
2
- export declare type GetContentOptions = import('./types.js').GetContentOptions;
2
+ import type { GetContentOptions } from './types.js';
3
3
  export declare function getContent(options: GetContentOptions): Promise<BuilderContent | null>;
4
- export declare const generateContentUrl: (options: GetContentOptions) => URL;
5
4
  /**
6
5
  * TO-DO: Handle error responses.
7
6
  */
@@ -1 +1 @@
1
- export declare function getFetch(): Promise<typeof global.fetch>;
1
+ export declare const fetch: typeof globalThis.fetch;
@@ -1 +1,3 @@
1
- export declare function getGlobalThis(): any;
1
+ /// <reference types="@types/node" />
2
+ /// <reference types="node" />
3
+ export declare function getGlobalThis(): typeof global;