@plasmicapp/loader-edge
Advanced tools
Comparing version 1.0.29 to 1.0.30
export { generateAllPaths, getActiveVariation, getMiddlewareResponse, rewriteWithoutTraits, rewriteWithTraits, } from './variation'; |
@@ -0,8 +1,164 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
'use strict' | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
generateAllPaths: () => generateAllPaths, | ||
getActiveVariation: () => getActiveVariation, | ||
getMiddlewareResponse: () => getMiddlewareResponse, | ||
rewriteWithTraits: () => rewriteWithTraits, | ||
rewriteWithoutTraits: () => rewriteWithoutTraits | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./loader-edge.cjs.production.min.js') | ||
} else { | ||
module.exports = require('./loader-edge.cjs.development.js') | ||
} | ||
// src/variation.ts | ||
var import_loader_splits = require("@plasmicapp/loader-splits"); | ||
// src/random.ts | ||
var getSeededRandomFunction = (strSeed) => { | ||
function cyrb128(str) { | ||
let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762; | ||
for (let i = 0, k; i < str.length; i++) { | ||
k = str.charCodeAt(i); | ||
h1 = h2 ^ Math.imul(h1 ^ k, 597399067); | ||
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233); | ||
h3 = h4 ^ Math.imul(h3 ^ k, 951274213); | ||
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179); | ||
} | ||
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067); | ||
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233); | ||
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213); | ||
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179); | ||
return [ | ||
(h1 ^ h2 ^ h3 ^ h4) >>> 0, | ||
(h2 ^ h1) >>> 0, | ||
(h3 ^ h1) >>> 0, | ||
(h4 ^ h1) >>> 0 | ||
]; | ||
} | ||
function sfc32(a, b, c, d) { | ||
return function() { | ||
a >>>= 0; | ||
b >>>= 0; | ||
c >>>= 0; | ||
d >>>= 0; | ||
let t = a + b | 0; | ||
a = b ^ b >>> 9; | ||
b = c + (c << 3) | 0; | ||
c = c << 21 | c >>> 11; | ||
d = d + 1 | 0; | ||
t = t + d | 0; | ||
c = c + t | 0; | ||
return (t >>> 0) / 4294967296; | ||
}; | ||
} | ||
const seed = cyrb128(strSeed); | ||
const rand = sfc32(seed[0], seed[1], seed[2], seed[3]); | ||
return rand; | ||
}; | ||
// src/variation.ts | ||
var DELIMITER = "__pm__"; | ||
var PLASMIC_SEED = "plasmic_seed"; | ||
var SEED_RANGE = 16; | ||
var getSeed = () => { | ||
return `${Math.floor(Math.random() * SEED_RANGE)}`; | ||
}; | ||
var rewriteWithoutTraits = (url) => { | ||
const [path, ...traitssArr] = url.split(DELIMITER); | ||
const traits = traitssArr.reduce((acc, elem) => { | ||
const [key, value] = elem.split("="); | ||
return __spreadProps(__spreadValues({}, acc), { | ||
[key]: value | ||
}); | ||
}, {}); | ||
return { | ||
path: path === "/" ? path : path.endsWith("/") ? path.substring(0, path.length - 1) : path, | ||
traits | ||
}; | ||
}; | ||
var expandTraits = (traits) => { | ||
const cmp = (a, b) => { | ||
return a < b ? -1 : a > b ? 1 : 0; | ||
}; | ||
return Object.keys(traits).sort(cmp).map((key) => `${DELIMITER}${key}=${traits[key]}`).join(""); | ||
}; | ||
var rewriteWithTraits = (path, traits) => { | ||
return `${path}${path.endsWith("/") ? "" : "/"}${expandTraits(traits)}`; | ||
}; | ||
var generateAllPaths = (path) => { | ||
const paths = [ | ||
path, | ||
...Array(SEED_RANGE).fill(0).map( | ||
(_, idx) => `${path}${path.endsWith("/") ? "" : "/"}__pm__${PLASMIC_SEED}=${idx}` | ||
) | ||
]; | ||
return paths; | ||
}; | ||
var getMiddlewareResponse = (opts) => { | ||
const newCookies = []; | ||
const seed = opts.cookies[PLASMIC_SEED] || getSeed(); | ||
if (!opts.cookies[PLASMIC_SEED]) { | ||
newCookies.push({ | ||
key: PLASMIC_SEED, | ||
value: seed | ||
}); | ||
} | ||
return { | ||
pathname: rewriteWithTraits(opts.path, __spreadValues({ | ||
[PLASMIC_SEED]: seed | ||
}, opts.traits)), | ||
cookies: newCookies | ||
}; | ||
}; | ||
var getActiveVariation = (opts) => { | ||
const { splits, traits, path } = opts; | ||
return (0, import_loader_splits.getActiveVariation)({ | ||
splits, | ||
traits: __spreadValues({ | ||
pageUrl: path | ||
}, traits), | ||
getKnownValue: () => void 0, | ||
updateKnownValue: () => null, | ||
getRandomValue: (key) => { | ||
var _a; | ||
const rand = getSeededRandomFunction(((_a = traits[PLASMIC_SEED]) != null ? _a : "") + key); | ||
return rand(); | ||
} | ||
}); | ||
}; | ||
//# sourceMappingURL=index.js.map |
export declare const getSeededRandomFunction: (strSeed: string) => () => number; |
import { Split } from '@plasmicapp/loader-fetcher'; | ||
declare type Traits = Record<string, string | number | boolean>; | ||
type Traits = Record<string, string | number | boolean>; | ||
export declare const rewriteWithoutTraits: (url: string) => { | ||
@@ -4,0 +4,0 @@ path: string; |
{ | ||
"version": "1.0.29", | ||
"version": "1.0.30", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"main": "./dist/index.js", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"files": [ | ||
@@ -13,8 +19,9 @@ "dist" | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build --target node", | ||
"build": "yarn build:types && yarn build:index", | ||
"build:types": "yarn tsc", | ||
"build:index": "node ../../build.mjs ./src/index.ts", | ||
"yalcp": "yalc publish --push", | ||
"test": "yarn --cwd=../.. test --passWithNoTests", | ||
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests", | ||
"lint": "tsdx lint", | ||
"lint": "eslint", | ||
"prepare": "if-env PREPARE_NO_BUILD=true || yarn build", | ||
@@ -24,36 +31,13 @@ "size": "size-limit", | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
}, | ||
"name": "@plasmicapp/loader-edge", | ||
"author": "Chung Wu", | ||
"module": "dist/loader-edge.esm.js", | ||
"size-limit": [ | ||
{ | ||
"path": "dist/loader-edge.cjs.production.min.js", | ||
"path": "./dist/index.js", | ||
"limit": "10 KB" | ||
}, | ||
{ | ||
"path": "dist/loader-edge.esm.js", | ||
"limit": "10 KB" | ||
} | ||
], | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.11.0", | ||
"husky": "^6.0.0", | ||
"size-limit": "^4.11.0", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.2.0" | ||
}, | ||
"dependencies": { | ||
"@plasmicapp/loader-fetcher": "1.0.23", | ||
"@plasmicapp/loader-splits": "1.0.28" | ||
"@plasmicapp/loader-fetcher": "1.0.24", | ||
"@plasmicapp/loader-splits": "1.0.29" | ||
}, | ||
@@ -63,3 +47,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "aed79bb7319dc8f42c185c212f9ba23f26591fd4" | ||
"gitHead": "1d6d699a0dfb9781ecac5e8df1dfc3a690c43559" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
1
1
15634
8
187
1
+ Added@plasmicapp/loader-fetcher@1.0.24(transitive)
+ Added@plasmicapp/loader-splits@1.0.29(transitive)
- Removed@plasmicapp/loader-fetcher@1.0.23(transitive)
- Removed@plasmicapp/loader-splits@1.0.28(transitive)