@zuplo/cli 7.7.13 → 7.7.15
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/test/esbuild-config.d.ts.map +1 -1
- package/dist/test/esbuild-config.js +3 -0
- package/dist/test/esbuild-config.js.map +1 -1
- package/node_modules/@posthog/core/dist/error-tracking/coercers/dom-exception-coercer.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/surveys/index.d.ts +1 -0
- package/node_modules/@posthog/core/dist/surveys/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/surveys/index.js +7 -0
- package/node_modules/@posthog/core/dist/surveys/index.mjs +1 -0
- package/node_modules/@posthog/core/dist/surveys/shuffling.d.ts +7 -0
- package/node_modules/@posthog/core/dist/surveys/shuffling.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/surveys/shuffling.js +70 -0
- package/node_modules/@posthog/core/dist/surveys/shuffling.mjs +29 -0
- package/node_modules/@posthog/core/package.json +4 -2
- package/node_modules/@posthog/core/src/error-tracking/coercers/dom-exception-coercer.ts +1 -1
- package/node_modules/@posthog/core/src/surveys/index.ts +1 -0
- package/node_modules/@posthog/core/src/surveys/shuffling.spec.ts +51 -0
- package/node_modules/@posthog/core/src/surveys/shuffling.ts +42 -0
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-XZD4NKH6.js +410 -0
- package/node_modules/@zuplo/runtime/out/esm/chunk-XZD4NKH6.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +27 -2
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/get-east-asian-width/index.js +8 -3
- package/node_modules/get-east-asian-width/lookup-data.js +1 -1
- package/node_modules/get-east-asian-width/lookup.js +4 -4
- package/node_modules/get-east-asian-width/package.json +1 -1
- package/package.json +11 -11
- package/node_modules/@zuplo/runtime/out/esm/chunk-VUNRXOEM.js +0 -410
- package/node_modules/@zuplo/runtime/out/esm/chunk-VUNRXOEM.js.map +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-VUNRXOEM.js.LEGAL.txt → chunk-XZD4NKH6.js.LEGAL.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-config.d.ts","sourceRoot":"","sources":["../../src/test/esbuild-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"esbuild-config.d.ts","sourceRoot":"","sources":["../../src/test/esbuild-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAqDzE"}
|
|
@@ -5,6 +5,9 @@ export function generateBuildOptionsForTest(argv) {
|
|
|
5
5
|
outdir: `${argv.dir}/${TEST_OUT_FOLDER}`,
|
|
6
6
|
external: ["chai", "dotenv/config", "node:test"],
|
|
7
7
|
platform: "node",
|
|
8
|
+
banner: {
|
|
9
|
+
js: 'import { createRequire as __zuploCreateRequire } from "node:module"; const require = __zuploCreateRequire(import.meta.url);',
|
|
10
|
+
},
|
|
8
11
|
sourcemap: true,
|
|
9
12
|
bundle: true,
|
|
10
13
|
treeShaking: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-config.js","sourceRoot":"","sources":["../../src/test/esbuild-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAGhF,MAAM,UAAU,2BAA2B,CAAC,IAAe;IACzD,OAAO;QAEL,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,eAAe,EAAE;QACxC,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,WAAW,CAAC;QAChD,QAAQ,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"esbuild-config.js","sourceRoot":"","sources":["../../src/test/esbuild-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAGhF,MAAM,UAAU,2BAA2B,CAAC,IAAe;IACzD,OAAO;QAEL,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,eAAe,EAAE;QACxC,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,WAAW,CAAC;QAChD,QAAQ,EAAE,MAAM;QA6BhB,MAAM,EAAE;YACN,EAAE,EAAE,6HAA6H;SAClI;QACD,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;QAEjB,MAAM,EAAE,KAAK;QAEb,YAAY,EAAE;YACZ,KAAK,EAAE,MAAM;SACd;QAED,OAAO,EAAE;YACP,kBAAkB,CAAC,IAAI,EAAE;gBACvB,aAAa,EAAE,EAAE;aAClB,CAAC;SACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { BuildOptions } from \"esbuild\";\nimport { TEST_OUT_FOLDER } from \"../common/constants.js\";\nimport { nodeTestPrepPlugin } from \"./esbuild-plugins/node-test-prep-plugin.js\";\nimport { Arguments } from \"./handler.js\";\n\nexport function generateBuildOptionsForTest(argv: Arguments): BuildOptions {\n return {\n // Put it under the .zuplo folder\n outdir: `${argv.dir}/${TEST_OUT_FOLDER}`,\n external: [\"chai\", \"dotenv/config\", \"node:test\"],\n platform: \"node\",\n // Keep esbuild's default `platform: \"node\"` field order (`main` before\n // `module`). That order is deliberate: esbuild's docs note some packages\n // \"incorrectly treat `module` as meaning 'browser code' instead of\n // 'ECMAScript module code' so this default behavior is required for\n // compatibility.\" Flipping it to `[\"module\", \"main\"]` would change\n // resolution for EVERY dependency of EVERY customer's test suite.\n //\n // The banner below is why we can keep that default. A CJS package with no\n // `exports` map gets its `main` (CJS) build bundled into this `format:\n // \"esm\"` output, where esbuild rewrites its `require(...)` calls to an\n // interop shim (`typeof require !== \"undefined\" ? require : throw`). In a\n // plain ESM module there is no `require`, so the shim THROWS at runtime —\n // the build succeeds and the failure lands at import time as\n // `Error: Dynamic require of \"node:stream\" is not supported`.\n // `@aws-sdk/client-bedrock-runtime` is the motivating case (it ships\n // `main: dist-cjs` / `module: dist-es`, no `exports`), and this is what\n // lets a fixture test drive the gateway with a real AWS SDK client.\n //\n // This banner is esbuild's own recommended fix for that error: it defines a\n // real `createRequire`-backed `require` in the ESM output, which esbuild's\n // shim then uses instead of throwing. Unlike reordering `mainFields`, it\n // changes resolution for NO other dependency — it only makes the leftover\n // builtin `require(...)` calls work. Safe because the output is always\n // `format: \"esm\"` below, where `import.meta.url` exists.\n //\n // The import is aliased so a test file that imports `createRequire`\n // itself does not collide with the banner's binding. `require` is the only\n // name the banner claims on purpose.\n banner: {\n js: 'import { createRequire as __zuploCreateRequire } from \"node:module\"; const require = __zuploCreateRequire(import.meta.url);',\n },\n sourcemap: true,\n bundle: true,\n treeShaking: true,\n // The format needs to be esm for Deno to work with it\n format: \"esm\",\n // Let's keep the extension as .ts since that is what Deno runs\n outExtension: {\n \".js\": \".mjs\",\n },\n // Here is our own plug-in to shim the responses\n plugins: [\n nodeTestPrepPlugin(argv, {\n \"@zuplo/test\": \"\",\n }),\n ],\n };\n}\n"]}
|
package/node_modules/@posthog/core/dist/error-tracking/coercers/dom-exception-coercer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-exception-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/dom-exception-coercer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dom-exception-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/dom-exception-coercer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAG/E,qBAAa,mBAAoB,YAAW,oBAAoB,CAAC,YAAY,CAAC;IAC5E,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY;IAIxC,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,eAAe,GAAG,aAAa;IAY9D,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,UAAU;CAGnB"}
|
|
@@ -4,4 +4,5 @@ export { applySurveyTranslation, detectSurveyLanguage, findBestTranslationMatch,
|
|
|
4
4
|
export { canSurveyActivateRepeatedly, doesSurveyActivateByEvent, isSurveyIterationBased } from './activation';
|
|
5
5
|
export { getSurveyIterationKey, isSurveyKeyForSurvey, type SurveyWithIteration } from './keys';
|
|
6
6
|
export { isMatchingRegex, isValidRegex, matchPropertyFilters, propertyComparisons } from './property-matching';
|
|
7
|
+
export { getDisplayOrderChoices, shuffle } from './shuffling';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/surveys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAC1F,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,qCAAqC,EACrC,qBAAqB,GACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC7G,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC9F,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/surveys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAC1F,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,qCAAqC,EACrC,qBAAqB,GACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC7G,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC9F,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -36,6 +36,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
36
|
doesSurveyActivateByEvent: ()=>external_activation_js_namespaceObject.doesSurveyActivateByEvent,
|
|
37
37
|
findBestTranslationMatch: ()=>external_translations_js_namespaceObject.findBestTranslationMatch,
|
|
38
38
|
getBaseLanguage: ()=>external_translations_js_namespaceObject.getBaseLanguage,
|
|
39
|
+
getDisplayOrderChoices: ()=>external_shuffling_js_namespaceObject.getDisplayOrderChoices,
|
|
39
40
|
getLanguageFromStoredPersonProperties: ()=>external_translations_js_namespaceObject.getLanguageFromStoredPersonProperties,
|
|
40
41
|
getLengthFromRules: ()=>external_validation_js_namespaceObject.getLengthFromRules,
|
|
41
42
|
getRequirementsHint: ()=>external_validation_js_namespaceObject.getRequirementsHint,
|
|
@@ -52,6 +53,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
52
53
|
matchPropertyFilters: ()=>external_property_matching_js_namespaceObject.matchPropertyFilters,
|
|
53
54
|
normalizeLanguageCode: ()=>external_translations_js_namespaceObject.normalizeLanguageCode,
|
|
54
55
|
propertyComparisons: ()=>external_property_matching_js_namespaceObject.propertyComparisons,
|
|
56
|
+
shuffle: ()=>external_shuffling_js_namespaceObject.shuffle,
|
|
55
57
|
surveyHasResponses: ()=>external_events_js_namespaceObject.surveyHasResponses
|
|
56
58
|
});
|
|
57
59
|
const external_validation_js_namespaceObject = require("./validation.js");
|
|
@@ -60,6 +62,7 @@ const external_translations_js_namespaceObject = require("./translations.js");
|
|
|
60
62
|
const external_activation_js_namespaceObject = require("./activation.js");
|
|
61
63
|
const external_keys_js_namespaceObject = require("./keys.js");
|
|
62
64
|
const external_property_matching_js_namespaceObject = require("./property-matching.js");
|
|
65
|
+
const external_shuffling_js_namespaceObject = require("./shuffling.js");
|
|
63
66
|
exports.SURVEY_LANGUAGE_PROPERTY = __webpack_exports__.SURVEY_LANGUAGE_PROPERTY;
|
|
64
67
|
exports.applySurveyTranslation = __webpack_exports__.applySurveyTranslation;
|
|
65
68
|
exports.buildSurveyResponseProperties = __webpack_exports__.buildSurveyResponseProperties;
|
|
@@ -68,6 +71,7 @@ exports.detectSurveyLanguage = __webpack_exports__.detectSurveyLanguage;
|
|
|
68
71
|
exports.doesSurveyActivateByEvent = __webpack_exports__.doesSurveyActivateByEvent;
|
|
69
72
|
exports.findBestTranslationMatch = __webpack_exports__.findBestTranslationMatch;
|
|
70
73
|
exports.getBaseLanguage = __webpack_exports__.getBaseLanguage;
|
|
74
|
+
exports.getDisplayOrderChoices = __webpack_exports__.getDisplayOrderChoices;
|
|
71
75
|
exports.getLanguageFromStoredPersonProperties = __webpack_exports__.getLanguageFromStoredPersonProperties;
|
|
72
76
|
exports.getLengthFromRules = __webpack_exports__.getLengthFromRules;
|
|
73
77
|
exports.getRequirementsHint = __webpack_exports__.getRequirementsHint;
|
|
@@ -84,6 +88,7 @@ exports.isValidRegex = __webpack_exports__.isValidRegex;
|
|
|
84
88
|
exports.matchPropertyFilters = __webpack_exports__.matchPropertyFilters;
|
|
85
89
|
exports.normalizeLanguageCode = __webpack_exports__.normalizeLanguageCode;
|
|
86
90
|
exports.propertyComparisons = __webpack_exports__.propertyComparisons;
|
|
91
|
+
exports.shuffle = __webpack_exports__.shuffle;
|
|
87
92
|
exports.surveyHasResponses = __webpack_exports__.surveyHasResponses;
|
|
88
93
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
89
94
|
"SURVEY_LANGUAGE_PROPERTY",
|
|
@@ -94,6 +99,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
94
99
|
"doesSurveyActivateByEvent",
|
|
95
100
|
"findBestTranslationMatch",
|
|
96
101
|
"getBaseLanguage",
|
|
102
|
+
"getDisplayOrderChoices",
|
|
97
103
|
"getLanguageFromStoredPersonProperties",
|
|
98
104
|
"getLengthFromRules",
|
|
99
105
|
"getRequirementsHint",
|
|
@@ -110,6 +116,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
110
116
|
"matchPropertyFilters",
|
|
111
117
|
"normalizeLanguageCode",
|
|
112
118
|
"propertyComparisons",
|
|
119
|
+
"shuffle",
|
|
113
120
|
"surveyHasResponses"
|
|
114
121
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
115
122
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -4,3 +4,4 @@ export { applySurveyTranslation, detectSurveyLanguage, findBestTranslationMatch,
|
|
|
4
4
|
export { canSurveyActivateRepeatedly, doesSurveyActivateByEvent, isSurveyIterationBased } from "./activation.mjs";
|
|
5
5
|
export { getSurveyIterationKey, isSurveyKeyForSurvey } from "./keys.mjs";
|
|
6
6
|
export { isMatchingRegex, isValidRegex, matchPropertyFilters, propertyComparisons } from "./property-matching.mjs";
|
|
7
|
+
export { getDisplayOrderChoices, shuffle } from "./shuffling.mjs";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MultipleSurveyQuestion } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Fisher-Yates shuffle without mutating the input array.
|
|
4
|
+
*/
|
|
5
|
+
export declare const shuffle: <T>(array: readonly T[]) => T[];
|
|
6
|
+
export declare const getDisplayOrderChoices: (question: Pick<MultipleSurveyQuestion, "choices" | "hasOpenChoice" | "shuffleOptions">) => string[];
|
|
7
|
+
//# sourceMappingURL=shuffling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shuffling.d.ts","sourceRoot":"","sources":["../../src/surveys/shuffling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAGtD;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,SAAS,CAAC,EAAE,KAAG,CAAC,EASjD,CAAA;AAUD,eAAO,MAAM,sBAAsB,GACjC,UAAU,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,eAAe,GAAG,gBAAgB,CAAC,KACrF,MAAM,EAcR,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
getDisplayOrderChoices: ()=>getDisplayOrderChoices,
|
|
32
|
+
shuffle: ()=>shuffle
|
|
33
|
+
});
|
|
34
|
+
const type_utils_js_namespaceObject = require("../utils/type-utils.js");
|
|
35
|
+
const shuffle = (array)=>{
|
|
36
|
+
const shuffled = [
|
|
37
|
+
...array
|
|
38
|
+
];
|
|
39
|
+
for(let index = shuffled.length - 1; index > 0; index--){
|
|
40
|
+
const swapIndex = Math.floor(Math.random() * (index + 1));
|
|
41
|
+
[shuffled[index], shuffled[swapIndex]] = [
|
|
42
|
+
shuffled[swapIndex],
|
|
43
|
+
shuffled[index]
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
return shuffled;
|
|
47
|
+
};
|
|
48
|
+
const reverseIfUnshuffled = (unshuffled, shuffled)=>{
|
|
49
|
+
if (shuffled.length > 1 && unshuffled.every((value, index)=>value === shuffled[index])) return shuffled.reverse();
|
|
50
|
+
return shuffled;
|
|
51
|
+
};
|
|
52
|
+
const getDisplayOrderChoices = (question)=>{
|
|
53
|
+
if (!question.shuffleOptions) return question.choices;
|
|
54
|
+
const choices = [
|
|
55
|
+
...question.choices
|
|
56
|
+
];
|
|
57
|
+
const openEndedChoice = question.hasOpenChoice ? choices.pop() ?? null : null;
|
|
58
|
+
const shuffledChoices = reverseIfUnshuffled(choices, shuffle(choices));
|
|
59
|
+
if (!(0, type_utils_js_namespaceObject.isNull)(openEndedChoice)) shuffledChoices.push(openEndedChoice);
|
|
60
|
+
return shuffledChoices;
|
|
61
|
+
};
|
|
62
|
+
exports.getDisplayOrderChoices = __webpack_exports__.getDisplayOrderChoices;
|
|
63
|
+
exports.shuffle = __webpack_exports__.shuffle;
|
|
64
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
65
|
+
"getDisplayOrderChoices",
|
|
66
|
+
"shuffle"
|
|
67
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
68
|
+
Object.defineProperty(exports, '__esModule', {
|
|
69
|
+
value: true
|
|
70
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isNull } from "../utils/type-utils.mjs";
|
|
2
|
+
const shuffle = (array)=>{
|
|
3
|
+
const shuffled = [
|
|
4
|
+
...array
|
|
5
|
+
];
|
|
6
|
+
for(let index = shuffled.length - 1; index > 0; index--){
|
|
7
|
+
const swapIndex = Math.floor(Math.random() * (index + 1));
|
|
8
|
+
[shuffled[index], shuffled[swapIndex]] = [
|
|
9
|
+
shuffled[swapIndex],
|
|
10
|
+
shuffled[index]
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
return shuffled;
|
|
14
|
+
};
|
|
15
|
+
const reverseIfUnshuffled = (unshuffled, shuffled)=>{
|
|
16
|
+
if (shuffled.length > 1 && unshuffled.every((value, index)=>value === shuffled[index])) return shuffled.reverse();
|
|
17
|
+
return shuffled;
|
|
18
|
+
};
|
|
19
|
+
const getDisplayOrderChoices = (question)=>{
|
|
20
|
+
if (!question.shuffleOptions) return question.choices;
|
|
21
|
+
const choices = [
|
|
22
|
+
...question.choices
|
|
23
|
+
];
|
|
24
|
+
const openEndedChoice = question.hasOpenChoice ? choices.pop() ?? null : null;
|
|
25
|
+
const shuffledChoices = reverseIfUnshuffled(choices, shuffle(choices));
|
|
26
|
+
if (!isNull(openEndedChoice)) shuffledChoices.push(openEndedChoice);
|
|
27
|
+
return shuffledChoices;
|
|
28
|
+
};
|
|
29
|
+
export { getDisplayOrderChoices, shuffle };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.54.
|
|
3
|
+
"version": "1.54.4",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@posthog/types": "^1.412.
|
|
73
|
+
"@posthog/types": "^1.412.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@rslib/core": "0.23.2",
|
|
@@ -79,12 +79,14 @@
|
|
|
79
79
|
"@posthog-tooling/tsconfig-base": "1.1.1"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
|
+
"check-types": "tsc --noEmit --project tsconfig.build.json",
|
|
82
83
|
"clean": "rimraf dist",
|
|
83
84
|
"lint": "oxlint --report-unused-disable-directives-severity error src",
|
|
84
85
|
"lint:fix": "oxlint --report-unused-disable-directives-severity error src --fix",
|
|
85
86
|
"build": "rslib build",
|
|
86
87
|
"dev": "rslib build -w",
|
|
87
88
|
"test:unit": "NODE_OPTIONS=--expose-gc vitest run",
|
|
89
|
+
"test:built": "node --test scripts/check-declaration-sourcemap.mjs",
|
|
88
90
|
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
89
91
|
}
|
|
90
92
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoercingContext, ErrorTrackingCoercer, ExceptionLike } from '
|
|
1
|
+
import { CoercingContext, ErrorTrackingCoercer, ExceptionLike } from '../types'
|
|
2
2
|
import { isBuiltin, isString } from '@/utils'
|
|
3
3
|
|
|
4
4
|
export class DOMExceptionCoercer implements ErrorTrackingCoercer<DOMException> {
|
|
@@ -19,3 +19,4 @@ export {
|
|
|
19
19
|
export { canSurveyActivateRepeatedly, doesSurveyActivateByEvent, isSurveyIterationBased } from './activation'
|
|
20
20
|
export { getSurveyIterationKey, isSurveyKeyForSurvey, type SurveyWithIteration } from './keys'
|
|
21
21
|
export { isMatchingRegex, isValidRegex, matchPropertyFilters, propertyComparisons } from './property-matching'
|
|
22
|
+
export { getDisplayOrderChoices, shuffle } from './shuffling'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { SurveyQuestionType } from '../types'
|
|
3
|
+
import { getDisplayOrderChoices, shuffle } from './shuffling'
|
|
4
|
+
|
|
5
|
+
afterEach(() => vi.restoreAllMocks())
|
|
6
|
+
|
|
7
|
+
describe('survey choice shuffling', () => {
|
|
8
|
+
const question = (choices: string[], shuffleOptions = true, hasOpenChoice = false) => ({
|
|
9
|
+
type: SurveyQuestionType.SingleChoice as const,
|
|
10
|
+
question: 'Pick one',
|
|
11
|
+
choices,
|
|
12
|
+
shuffleOptions,
|
|
13
|
+
hasOpenChoice,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('uses Fisher-Yates without mutating the input', () => {
|
|
17
|
+
vi.spyOn(Math, 'random').mockReturnValue(0)
|
|
18
|
+
const source = Object.freeze(['a', 'b', 'c'])
|
|
19
|
+
expect(shuffle(source)).toEqual(['b', 'c', 'a'])
|
|
20
|
+
expect(source).toEqual(['a', 'b', 'c'])
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it.each([false, true])('keeps Other last without mutating choices (open=%s)', (hasOpenChoice) => {
|
|
24
|
+
vi.spyOn(Math, 'random').mockReturnValue(0)
|
|
25
|
+
const source = question(['a', 'b', 'c', ...(hasOpenChoice ? ['Other'] : [])], true, hasOpenChoice)
|
|
26
|
+
Object.freeze(source.choices)
|
|
27
|
+
Object.freeze(source)
|
|
28
|
+
expect(getDisplayOrderChoices(source)).toEqual(['b', 'c', 'a', ...(hasOpenChoice ? ['Other'] : [])])
|
|
29
|
+
expect(getDisplayOrderChoices(source)).toEqual(['b', 'c', 'a', ...(hasOpenChoice ? ['Other'] : [])])
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('reverses the regular choices if randomness leaves their order unchanged', () => {
|
|
33
|
+
vi.spyOn(Math, 'random').mockReturnValue(0.999999)
|
|
34
|
+
expect(getDisplayOrderChoices(question(['a', 'b', 'c', 'Other'], true, true))).toEqual(['c', 'b', 'a', 'Other'])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it.each([false, undefined])('preserves configured order when shuffleOptions=%s', (shuffleOptions) => {
|
|
38
|
+
const source = { ...question(['a', 'b', 'Other'], false, true), shuffleOptions }
|
|
39
|
+
expect(getDisplayOrderChoices(source)).toBe(source.choices)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it.each([[], ['Other'], ['a', 'Other'], ['a', 'a', 'Other'], ['a', 'b', '']])(
|
|
43
|
+
'retains every choice in %j',
|
|
44
|
+
(...choices) => {
|
|
45
|
+
const source = question(choices, true, true)
|
|
46
|
+
const result = getDisplayOrderChoices(source)
|
|
47
|
+
expect([...result].sort()).toEqual([...choices].sort())
|
|
48
|
+
if (choices.length) expect(result[result.length - 1]).toBe(choices[choices.length - 1])
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MultipleSurveyQuestion } from '../types'
|
|
2
|
+
import { isNull } from '../utils/type-utils'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fisher-Yates shuffle without mutating the input array.
|
|
6
|
+
*/
|
|
7
|
+
export const shuffle = <T>(array: readonly T[]): T[] => {
|
|
8
|
+
const shuffled = [...array]
|
|
9
|
+
|
|
10
|
+
for (let index = shuffled.length - 1; index > 0; index--) {
|
|
11
|
+
const swapIndex = Math.floor(Math.random() * (index + 1))
|
|
12
|
+
;[shuffled[index], shuffled[swapIndex]] = [shuffled[swapIndex], shuffled[index]]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return shuffled
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const reverseIfUnshuffled = <T>(unshuffled: readonly T[], shuffled: T[]): T[] => {
|
|
19
|
+
if (shuffled.length > 1 && unshuffled.every((value, index) => value === shuffled[index])) {
|
|
20
|
+
return shuffled.reverse()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return shuffled
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const getDisplayOrderChoices = (
|
|
27
|
+
question: Pick<MultipleSurveyQuestion, 'choices' | 'hasOpenChoice' | 'shuffleOptions'>
|
|
28
|
+
): string[] => {
|
|
29
|
+
if (!question.shuffleOptions) {
|
|
30
|
+
return question.choices
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const choices = [...question.choices]
|
|
34
|
+
const openEndedChoice = question.hasOpenChoice ? (choices.pop() ?? null) : null
|
|
35
|
+
const shuffledChoices = reverseIfUnshuffled(choices, shuffle(choices))
|
|
36
|
+
|
|
37
|
+
if (!isNull(openEndedChoice)) {
|
|
38
|
+
shuffledChoices.push(openEndedChoice)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return shuffledChoices
|
|
42
|
+
}
|