@naturalcycles/abba 2.2.0 → 2.3.2
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/abba.d.ts +3 -2
- package/dist/abba.js +10 -4
- package/package.json +18 -20
- package/src/abba.ts +11 -4
package/dist/abba.d.ts
CHANGED
|
@@ -18,9 +18,10 @@ export declare class Abba {
|
|
|
18
18
|
getAllExperimentsWithBucketsNoCache(opts?: GetAllExperimentsOpts): Promise<ExperimentWithBuckets[]>;
|
|
19
19
|
getUserExperiments(userId: string): Promise<UserExperiment[]>;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Changes all user assignments from one userId to another, as long as no
|
|
22
|
+
* assignment for a given experiment already exists with the new userId.
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
mergeAssignmentsForUserIds(fromUserId: string, intoUserId: string): Promise<void>;
|
|
24
25
|
/**
|
|
25
26
|
* Creates a new experiment.
|
|
26
27
|
* Cold method.
|
package/dist/abba.js
CHANGED
|
@@ -58,11 +58,17 @@ export class Abba {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Changes all user assignments from one userId to another, as long as no
|
|
62
|
+
* assignment for a given experiment already exists with the new userId.
|
|
62
63
|
*/
|
|
63
|
-
async
|
|
64
|
-
const
|
|
65
|
-
await this.userAssignmentDao.
|
|
64
|
+
async mergeAssignmentsForUserIds(fromUserId, intoUserId) {
|
|
65
|
+
const fromAssignments = await this.userAssignmentDao.getBy('userId', fromUserId);
|
|
66
|
+
const existingIntoAssignments = await this.userAssignmentDao.getBy('userId', intoUserId);
|
|
67
|
+
await pMap(fromAssignments, async (from) => {
|
|
68
|
+
if (!existingIntoAssignments.some(into => into.experimentId === from.experimentId)) {
|
|
69
|
+
await this.userAssignmentDao.patch(from, { userId: intoUserId });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
66
72
|
}
|
|
67
73
|
/**
|
|
68
74
|
* Creates a new experiment.
|
package/package.json
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/abba",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.2
|
|
5
|
-
"scripts": {
|
|
6
|
-
"prepare": "husky",
|
|
7
|
-
"build": "dev-lib build",
|
|
8
|
-
"test": "dev-lib test",
|
|
9
|
-
"lint": "dev-lib lint",
|
|
10
|
-
"bt": "dev-lib bt",
|
|
11
|
-
"lbt": "dev-lib lbt"
|
|
12
|
-
},
|
|
4
|
+
"version": "2.3.2",
|
|
13
5
|
"dependencies": {
|
|
14
6
|
"@naturalcycles/db-lib": "^10",
|
|
15
7
|
"@naturalcycles/js-lib": "^15",
|
|
16
8
|
"@naturalcycles/nodejs-lib": "^14",
|
|
17
|
-
"semver": "^7"
|
|
9
|
+
"semver": "^7",
|
|
10
|
+
"tslib": "^2"
|
|
18
11
|
},
|
|
19
12
|
"devDependencies": {
|
|
20
|
-
"@naturalcycles/dev-lib": "
|
|
21
|
-
"@types/
|
|
22
|
-
"@types/semver": "^7",
|
|
23
|
-
"@vitest/coverage-v8": "^3",
|
|
24
|
-
"tsx": "^4",
|
|
25
|
-
"vitest": "^3"
|
|
13
|
+
"@naturalcycles/dev-lib": "*",
|
|
14
|
+
"@types/semver": "^7"
|
|
26
15
|
},
|
|
27
16
|
"files": [
|
|
28
17
|
"dist",
|
|
@@ -35,11 +24,12 @@
|
|
|
35
24
|
"main": "dist/index.js",
|
|
36
25
|
"types": "dist/index.d.ts",
|
|
37
26
|
"publishConfig": {
|
|
38
|
-
"access": "
|
|
27
|
+
"access": "public"
|
|
39
28
|
},
|
|
40
29
|
"repository": {
|
|
41
30
|
"type": "git",
|
|
42
|
-
"url": "
|
|
31
|
+
"url": "git@github.com:NaturalCycles/js-libs.git",
|
|
32
|
+
"directory": "packages/abba"
|
|
43
33
|
},
|
|
44
34
|
"engines": {
|
|
45
35
|
"node": ">=22.10.0"
|
|
@@ -47,5 +37,13 @@
|
|
|
47
37
|
"description": "AB test assignment configuration tool for Node.js",
|
|
48
38
|
"author": "Natural Cycles Team",
|
|
49
39
|
"license": "MIT",
|
|
50
|
-
"
|
|
51
|
-
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "dev-lib build",
|
|
42
|
+
"test": "dev-lib test",
|
|
43
|
+
"lint": "dev-lib lint",
|
|
44
|
+
"bt": "dev-lib bt",
|
|
45
|
+
"clean": "dev-lib clean",
|
|
46
|
+
"typecheck": "dev-lib typecheck",
|
|
47
|
+
"check": "dev-lib check"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/abba.ts
CHANGED
|
@@ -94,11 +94,18 @@ export class Abba {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* Changes all user assignments from one userId to another, as long as no
|
|
98
|
+
* assignment for a given experiment already exists with the new userId.
|
|
98
99
|
*/
|
|
99
|
-
async
|
|
100
|
-
const
|
|
101
|
-
await this.userAssignmentDao.
|
|
100
|
+
async mergeAssignmentsForUserIds(fromUserId: string, intoUserId: string): Promise<void> {
|
|
101
|
+
const fromAssignments = await this.userAssignmentDao.getBy('userId', fromUserId)
|
|
102
|
+
const existingIntoAssignments = await this.userAssignmentDao.getBy('userId', intoUserId)
|
|
103
|
+
|
|
104
|
+
await pMap(fromAssignments, async from => {
|
|
105
|
+
if (!existingIntoAssignments.some(into => into.experimentId === from.experimentId)) {
|
|
106
|
+
await this.userAssignmentDao.patch(from, { userId: intoUserId })
|
|
107
|
+
}
|
|
108
|
+
})
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
/**
|