@swell/apps-sdk 1.0.174 → 1.0.175

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/dist/index.cjs CHANGED
@@ -4020,7 +4020,7 @@ var Cache = class {
4020
4020
  /**
4021
4021
  * Always fetches fresh data and updates cache
4022
4022
  * Deduplicates concurrent requests with the same key
4023
- *
4023
+ *
4024
4024
  * @param key Cache key
4025
4025
  * @param fetchFn Function to fetch fresh data
4026
4026
  * @param ttl Time to live in milliseconds (default: DEFAULT_SWR_TTL)
@@ -14766,6 +14766,14 @@ var RenderDrop = class extends import_liquidjs14.Drop {
14766
14766
  // src/liquid/index.ts
14767
14767
  var import_liquidjs34 = require("liquidjs");
14768
14768
 
14769
+ // src/utils/escape.ts
14770
+ function replacerUnescape(match) {
14771
+ return match.includes('\\"') ? JSON.parse(`"${match}"`) : match;
14772
+ }
14773
+ function unescapeLiquidSyntax(template) {
14774
+ return template.replace(/\{\{.*?\}\}/g, replacerUnescape);
14775
+ }
14776
+
14769
14777
  // src/liquid/tags/assign.ts
14770
14778
  var import_liquidjs15 = require("liquidjs");
14771
14779
  function bind(_liquidSwell) {
@@ -15274,28 +15282,30 @@ var import_liquidjs24 = require("liquidjs");
15274
15282
  function bind10(liquidSwell) {
15275
15283
  return class RenderTag extends import_liquidjs24.RenderTag {
15276
15284
  *render(ctx, emitter) {
15277
- const { liquid, hash } = this;
15278
- const filepath = yield renderFilePath(
15279
- this["file"],
15285
+ const self = this;
15286
+ const { liquid } = this;
15287
+ const { hash } = self;
15288
+ const filename = yield renderFilePath(
15289
+ self["file"],
15280
15290
  ctx,
15281
15291
  liquid
15282
15292
  );
15283
- (0, import_liquidjs24.assert)(filepath, () => `illegal file path "${filepath}"`);
15284
- const themeConfig = yield liquidSwell.getComponentPath(filepath).then(
15285
- (fileName) => liquidSwell.getThemeConfig(fileName)
15293
+ (0, import_liquidjs24.assert)(filename, () => `illegal file path "${filename}"`);
15294
+ const configPath = yield liquidSwell.getComponentPath(
15295
+ filename
15286
15296
  );
15287
15297
  const childCtx = ctx.spawn();
15288
15298
  const scope = childCtx.bottom();
15289
15299
  (0, import_lodash_es9.assign)(scope, yield hash.render(ctx));
15290
15300
  const parentSection = yield ctx._get(["section"]);
15291
15301
  if (parentSection) (0, import_lodash_es9.assign)(scope, { section: parentSection });
15292
- if (this["with"]) {
15293
- const { value, alias } = this["with"];
15294
- const aliasName = alias || filepath;
15302
+ if (self["with"]) {
15303
+ const { value, alias } = self["with"];
15304
+ const aliasName = alias || filename;
15295
15305
  scope[aliasName] = yield (0, import_liquidjs24.evalToken)(value, ctx);
15296
15306
  }
15297
- if (this["for"]) {
15298
- const { value, alias } = this["for"];
15307
+ if (self["for"]) {
15308
+ const { value, alias } = self["for"];
15299
15309
  let collection = yield (0, import_liquidjs24.evalToken)(value, ctx);
15300
15310
  collection = yield resolveEnumerable(collection);
15301
15311
  scope["forloop"] = new ForloopDrop(
@@ -15305,13 +15315,23 @@ function bind10(liquidSwell) {
15305
15315
  );
15306
15316
  for (const item of collection) {
15307
15317
  scope[alias] = item;
15308
- const output = yield liquidSwell.renderTemplate(themeConfig, scope);
15309
- emitter.write(output);
15318
+ const templates = yield liquid._parseFile(
15319
+ configPath,
15320
+ childCtx.sync,
15321
+ void 0,
15322
+ self["currentFile"]
15323
+ );
15324
+ yield liquid.renderer.renderTemplates(templates, childCtx, emitter);
15310
15325
  scope["forloop"].next();
15311
15326
  }
15312
15327
  } else {
15313
- const output = yield liquidSwell.renderTemplate(themeConfig, scope);
15314
- emitter.write(output);
15328
+ const templates = yield liquid._parseFile(
15329
+ configPath,
15330
+ childCtx.sync,
15331
+ void 0,
15332
+ self["currentFile"]
15333
+ );
15334
+ yield liquid.renderer.renderTemplates(templates, childCtx, emitter);
15315
15335
  }
15316
15336
  }
15317
15337
  };
@@ -16911,13 +16931,15 @@ var LiquidSwell30 = class extends import_liquidjs34.Liquid {
16911
16931
  }) {
16912
16932
  getThemeConfig = getThemeConfig || theme.getThemeConfig.bind(theme);
16913
16933
  extName = extName || "liquid";
16934
+ const fs = new LiquidFS(extName);
16914
16935
  super({
16915
- cache: false,
16936
+ cache: true,
16916
16937
  relativeReference: false,
16917
- fs: getLiquidFS(getThemeConfig, extName),
16938
+ fs,
16918
16939
  ownPropertyOnly: false,
16919
16940
  operators: swellOperators
16920
16941
  });
16942
+ fs.liquidSwell = this;
16921
16943
  this.theme = theme;
16922
16944
  this.getThemeConfig = getThemeConfig;
16923
16945
  this.getThemeTemplateConfigByType = getThemeTemplateConfigByType || theme.getThemeTemplateConfigByType.bind(theme);
@@ -16960,41 +16982,36 @@ var LiquidSwell30 = class extends import_liquidjs34.Liquid {
16960
16982
  function resolveFilePath(fileName, extName) {
16961
16983
  return `theme/${fileName}.${extName}`;
16962
16984
  }
16963
- function getLiquidFS(getThemeConfig, extName) {
16964
- return {
16965
- /** read a file asynchronously */
16966
- async readFile(filePath) {
16967
- const resolvedPath = resolveFilePath(filePath, extName);
16968
- return getThemeConfig(resolvedPath).then(
16969
- (template) => template?.file_data || `<!-- theme template not found: ${resolvedPath} -->`
16970
- );
16971
- },
16972
- /** check if a file exists asynchronously */
16973
- async exists(_filePath) {
16974
- return true;
16975
- },
16976
- /** read a file synchronously */
16977
- readFileSync(_filePath) {
16978
- return "";
16979
- },
16980
- /** check if a file exists synchronously */
16981
- existsSync(_filePath) {
16982
- return false;
16983
- },
16984
- /** check if file is contained in `root`, always return `true` by default. Warning: not setting this could expose path traversal vulnerabilities. */
16985
- contains(_root, _file) {
16986
- return true;
16987
- },
16988
- /** resolve a file against directory, for given `ext` option */
16989
- resolve(_dir, file, _ext) {
16990
- return file;
16991
- },
16992
- /** fallback file for lookup failure */
16993
- fallback(_filePath) {
16994
- return;
16995
- }
16996
- };
16997
- }
16985
+ var LiquidFS = class {
16986
+ liquidSwell;
16987
+ constructor(_extName) {
16988
+ }
16989
+ async readFile(filePath) {
16990
+ const template = await this.liquidSwell.getThemeConfig(filePath);
16991
+ return unescapeLiquidSyntax(
16992
+ template?.file_data || `<!-- theme template not found: ${filePath} -->`
16993
+ );
16994
+ }
16995
+ async exists(filePath) {
16996
+ const template = await this.liquidSwell.getThemeConfig(filePath);
16997
+ return Boolean(template);
16998
+ }
16999
+ readFileSync(_filePath) {
17000
+ return "";
17001
+ }
17002
+ existsSync(_filePath) {
17003
+ return false;
17004
+ }
17005
+ contains(_root, _file) {
17006
+ return true;
17007
+ }
17008
+ resolve(_dir, file, _ext) {
17009
+ return file;
17010
+ }
17011
+ fallback(_filePath) {
17012
+ return;
17013
+ }
17014
+ };
16998
17015
 
16999
17016
  // src/theme/theme-loader.ts
17000
17017
  var MAX_INDIVIDUAL_CONFIGS_TO_FETCH = 50;
@@ -19018,12 +19035,6 @@ function parseJsonConfig(config) {
19018
19035
  return {};
19019
19036
  }
19020
19037
  }
19021
- function replacerUnescape(match) {
19022
- return match.includes('\\"') ? JSON.parse(`"${match}"`) : match;
19023
- }
19024
- function unescapeLiquidSyntax(template) {
19025
- return template.replace(/\{\{.*?\}\}/g, replacerUnescape);
19026
- }
19027
19038
  function extractSchemaTag(template) {
19028
19039
  const list = template.match(
19029
19040
  /\{%-?\s*schema\s*-?%\}(.*)\{%-?\s*endschema\s*-?%\}/s