@naturalcycles/abba 1.22.1 → 1.23.0

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.js CHANGED
@@ -134,10 +134,12 @@ class Abba {
134
134
  const existingAssignments = await this.userAssignmentDao.getBy('userId', userId);
135
135
  const existing = existingAssignments.find(a => a.experimentId === experiment.id);
136
136
  if (existing) {
137
+ const bucket = buckets.find(b => b.id === existing.bucketId);
137
138
  return {
138
139
  ...existing,
139
140
  experimentKey: experiment.key,
140
- bucketKey: buckets.find(b => b.id === existing.bucketId)?.key || null,
141
+ bucketKey: bucket?.key || null,
142
+ bucketData: bucket?.data || null,
141
143
  };
142
144
  }
143
145
  // No existing assignment, but we don't want to generate a new one
@@ -153,10 +155,12 @@ class Abba {
153
155
  if (!assignment)
154
156
  return null;
155
157
  const newAssignment = await this.userAssignmentDao.save(assignment);
158
+ const bucket = buckets.find(b => b.id === newAssignment.bucketId);
156
159
  return {
157
160
  ...newAssignment,
158
161
  experimentKey: experiment.key,
159
- bucketKey: buckets.find(b => b.id === newAssignment.bucketId)?.key || null,
162
+ bucketKey: bucket?.key || null,
163
+ bucketData: bucket?.data || null,
160
164
  };
161
165
  }
162
166
  /**
@@ -174,6 +178,7 @@ class Abba {
174
178
  ...assignment,
175
179
  experimentKey: experiment.key,
176
180
  bucketKey: bucket?.key || null,
181
+ bucketData: bucket?.data || null,
177
182
  };
178
183
  });
179
184
  }
@@ -195,10 +200,12 @@ class Abba {
195
200
  for (const experiment of availableExperiments) {
196
201
  const existing = existingAssignments.find(ua => ua.experimentId === experiment.id);
197
202
  if (existing) {
203
+ const bucket = experiment.buckets.find(b => b.id === existing.bucketId);
198
204
  assignments.push({
199
205
  ...existing,
200
206
  experimentKey: experiment.key,
201
- bucketKey: experiment.buckets.find(b => b.id === existing.bucketId)?.key || null,
207
+ bucketKey: bucket?.key || null,
208
+ bucketData: bucket?.data || null,
202
209
  });
203
210
  }
204
211
  else if (!existingOnly && (0, util_1.canGenerateNewAssignments)(experiment, exclusionSet)) {
@@ -206,10 +213,12 @@ class Abba {
206
213
  if (assignment) {
207
214
  const created = this.userAssignmentDao.create(assignment);
208
215
  newAssignments.push(created);
216
+ const bucket = experiment.buckets.find(b => b.id === created.bucketId);
209
217
  assignments.push({
210
218
  ...created,
211
219
  experimentKey: experiment.key,
212
- bucketKey: experiment.buckets.find(b => b.id === created.bucketId)?.key || null,
220
+ bucketKey: bucket?.key || null,
221
+ bucketData: bucket?.data || null,
213
222
  });
214
223
  // Prevent future exclusion clashes
215
224
  experiment.exclusions.forEach(experimentId => exclusionSet.add(experimentId));
package/dist/types.d.ts CHANGED
@@ -51,6 +51,7 @@ export type UserAssignment = BaseDBEntity & {
51
51
  export type GeneratedUserAssignment = Saved<UserAssignment> & {
52
52
  experimentKey: string;
53
53
  bucketKey: string | null;
54
+ bucketData: AnyObject | null;
54
55
  };
55
56
  export type SegmentationData = AnyObject;
56
57
  export declare enum AssignmentStatus {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
- "version": "1.22.1",
3
+ "version": "1.23.0",
4
4
  "scripts": {
5
5
  "prepare": "husky"
6
6
  },
package/src/abba.ts CHANGED
@@ -189,10 +189,12 @@ export class Abba {
189
189
  const existingAssignments = await this.userAssignmentDao.getBy('userId', userId)
190
190
  const existing = existingAssignments.find(a => a.experimentId === experiment.id)
191
191
  if (existing) {
192
+ const bucket = buckets.find(b => b.id === existing.bucketId)
192
193
  return {
193
194
  ...existing,
194
195
  experimentKey: experiment.key,
195
- bucketKey: buckets.find(b => b.id === existing.bucketId)?.key || null,
196
+ bucketKey: bucket?.key || null,
197
+ bucketData: bucket?.data || null,
196
198
  }
197
199
  }
198
200
 
@@ -211,10 +213,13 @@ export class Abba {
211
213
 
212
214
  const newAssignment = await this.userAssignmentDao.save(assignment)
213
215
 
216
+ const bucket = buckets.find(b => b.id === newAssignment.bucketId)
217
+
214
218
  return {
215
219
  ...newAssignment,
216
220
  experimentKey: experiment.key,
217
- bucketKey: buckets.find(b => b.id === newAssignment.bucketId)?.key || null,
221
+ bucketKey: bucket?.key || null,
222
+ bucketData: bucket?.data || null,
218
223
  }
219
224
  }
220
225
 
@@ -233,6 +238,7 @@ export class Abba {
233
238
  ...assignment,
234
239
  experimentKey: experiment.key,
235
240
  bucketKey: bucket?.key || null,
241
+ bucketData: bucket?.data || null,
236
242
  }
237
243
  })
238
244
  }
@@ -265,20 +271,24 @@ export class Abba {
265
271
  for (const experiment of availableExperiments) {
266
272
  const existing = existingAssignments.find(ua => ua.experimentId === experiment.id)
267
273
  if (existing) {
274
+ const bucket = experiment.buckets.find(b => b.id === existing.bucketId)
268
275
  assignments.push({
269
276
  ...existing,
270
277
  experimentKey: experiment.key,
271
- bucketKey: experiment.buckets.find(b => b.id === existing.bucketId)?.key || null,
278
+ bucketKey: bucket?.key || null,
279
+ bucketData: bucket?.data || null,
272
280
  })
273
281
  } else if (!existingOnly && canGenerateNewAssignments(experiment, exclusionSet)) {
274
282
  const assignment = generateUserAssignmentData(experiment, userId, segmentationData)
275
283
  if (assignment) {
276
284
  const created = this.userAssignmentDao.create(assignment)
277
285
  newAssignments.push(created)
286
+ const bucket = experiment.buckets.find(b => b.id === created.bucketId)
278
287
  assignments.push({
279
288
  ...created,
280
289
  experimentKey: experiment.key,
281
- bucketKey: experiment.buckets.find(b => b.id === created.bucketId)?.key || null,
290
+ bucketKey: bucket?.key || null,
291
+ bucketData: bucket?.data || null,
282
292
  })
283
293
  // Prevent future exclusion clashes
284
294
  experiment.exclusions.forEach(experimentId => exclusionSet.add(experimentId))
package/src/types.ts CHANGED
@@ -58,6 +58,7 @@ export type UserAssignment = BaseDBEntity & {
58
58
  export type GeneratedUserAssignment = Saved<UserAssignment> & {
59
59
  experimentKey: string
60
60
  bucketKey: string | null
61
+ bucketData: AnyObject | null
61
62
  }
62
63
 
63
64
  export type SegmentationData = AnyObject