@tellescope/sdk 1.68.7 → 1.68.9

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.
@@ -60,6 +60,7 @@ import crypto from "crypto";
60
60
  import * as buffer from "buffer"; // only node >=15.7.0
61
61
  import { fieldsToValidationOld, mongoIdStringRequired, } from "@tellescope/validation";
62
62
  import { Session, EnduserSession } from "../sdk";
63
+ import { weighted_round_robin } from "@tellescope/utilities";
63
64
  import { DEFAULT_OPERATIONS, PLACEHOLDER_ID } from "@tellescope/constants";
64
65
  import { schema, } from "@tellescope/schema";
65
66
  import { assert, async_test, log_header, wait, } from "@tellescope/testing";
@@ -6758,10 +6759,12 @@ var tests = {
6758
6759
  ticket_threads: NO_TEST,
6759
6760
  ticket_thread_comments: NO_TEST,
6760
6761
  configurations: NO_TEST,
6762
+ group_mms_conversations: NO_TEST,
6761
6763
  };
6762
6764
  var TRACK_OPEN_IMAGE = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=", 'base64');
6763
6765
  var validate_schema = function () {
6764
6766
  var _a;
6767
+ log_header("Validate Schema");
6765
6768
  var endpoints = new Set([]);
6766
6769
  var modelName = undefined;
6767
6770
  for (modelName in schema) {
@@ -6783,6 +6786,158 @@ var validate_schema = function () {
6783
6786
  }
6784
6787
  }
6785
6788
  };
6789
+ var test_weighted_round_robin = function () { return __awaiter(void 0, void 0, void 0, function () {
6790
+ var testUsers, userIds, testAssignments, run_assignment_simulation;
6791
+ return __generator(this, function (_a) {
6792
+ switch (_a.label) {
6793
+ case 0:
6794
+ log_header("Test validate_weighted_round_robin");
6795
+ testUsers = [
6796
+ { id: '0', ticketAssignmentPriority: undefined },
6797
+ { id: '1', ticketAssignmentPriority: 1 },
6798
+ { id: '2', ticketAssignmentPriority: 2 },
6799
+ { id: '3', ticketAssignmentPriority: 3 },
6800
+ ];
6801
+ userIds = testUsers.map(function (u) { return u.id; });
6802
+ testAssignments = testUsers.map(function (u, i) { return ({
6803
+ id: i.toString(),
6804
+ key: 'test',
6805
+ timestamp: Date.now() - 1000,
6806
+ userId: u.id,
6807
+ }); });
6808
+ return [4 /*yield*/, async_test("Both empty", function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
6809
+ return [2 /*return*/, weighted_round_robin({ assignments: [], users: [] })];
6810
+ }); }); }, { onResult: function (r) { return r.selected === undefined; } })];
6811
+ case 1:
6812
+ _a.sent();
6813
+ return [4 /*yield*/, async_test("Single user, empty assignment", function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
6814
+ return [2 /*return*/, weighted_round_robin({ assignments: [], users: [testUsers[0]] })];
6815
+ }); }); }, { onResult: function (r) { return r.selected === testUsers[0].id; } })];
6816
+ case 2:
6817
+ _a.sent();
6818
+ return [4 /*yield*/, async_test("Both singletons", function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
6819
+ return [2 /*return*/, weighted_round_robin({ assignments: [testAssignments[0]], users: [testUsers[0]] })];
6820
+ }); }); }, { onResult: function (r) { return r.selected === testUsers[0].id; } })];
6821
+ case 3:
6822
+ _a.sent();
6823
+ run_assignment_simulation = function (_a) {
6824
+ var iterations = _a.iterations, expectedSelections = _a.expectedSelections, _b = _a.users, users = _b === void 0 ? testUsers : _b, _c = _a.title, title = _c === void 0 ? "Simulation ".concat(iterations) : _c;
6825
+ var assignments = [];
6826
+ var selections = [];
6827
+ for (var i = 0; i < iterations; i++) {
6828
+ if (assignments.length !== i) {
6829
+ throw new Error("Invariant Violation: assignment not saved in history");
6830
+ }
6831
+ var selected = weighted_round_robin({ assignments: assignments, users: users }).selected;
6832
+ selections.push(selected);
6833
+ var assignment = {
6834
+ id: i.toString(),
6835
+ userId: selected || '',
6836
+ key: 'test',
6837
+ timestamp: i, // simply ensures increasing timestamps per assignment
6838
+ };
6839
+ // ensure that assignment order doesn't matter (e.g. weighted_round_robin sorts internally)
6840
+ if (i % 2 === 0) {
6841
+ assignments.push(assignment); // add to back
6842
+ }
6843
+ else {
6844
+ assignments.unshift(assignment); // add to front
6845
+ }
6846
+ }
6847
+ assert(objects_equivalent(selections, expectedSelections), title + '\n' + JSON.stringify({ expected: expectedSelections, got: selections }, null, 2), title);
6848
+ };
6849
+ run_assignment_simulation({ expectedSelections: [], iterations: 0 });
6850
+ run_assignment_simulation({ expectedSelections: [userIds[0]], iterations: 1 });
6851
+ run_assignment_simulation({ expectedSelections: [userIds[0], userIds[1]], iterations: 2 });
6852
+ run_assignment_simulation({ expectedSelections: [userIds[0], userIds[1], userIds[2]], iterations: 3 });
6853
+ run_assignment_simulation({ expectedSelections: [userIds[0], userIds[1], userIds[2], userIds[3]], iterations: 4 });
6854
+ run_assignment_simulation({ iterations: 5,
6855
+ expectedSelections: [
6856
+ userIds[0], userIds[1], userIds[2], userIds[3],
6857
+ userIds[0],
6858
+ ],
6859
+ });
6860
+ run_assignment_simulation({ iterations: 6, expectedSelections: [
6861
+ userIds[0], userIds[1], userIds[2], userIds[3],
6862
+ userIds[0], userIds[2],
6863
+ ] });
6864
+ run_assignment_simulation({ iterations: 7, expectedSelections: [
6865
+ userIds[0], userIds[1], userIds[2], userIds[3],
6866
+ userIds[0], userIds[2], userIds[3],
6867
+ ] });
6868
+ run_assignment_simulation({ iterations: 8, expectedSelections: [
6869
+ userIds[0], userIds[1], userIds[2], userIds[3],
6870
+ userIds[0], userIds[2], userIds[3],
6871
+ userIds[0],
6872
+ ] });
6873
+ run_assignment_simulation({ iterations: 9,
6874
+ expectedSelections: [
6875
+ userIds[0], userIds[1], userIds[2], userIds[3],
6876
+ userIds[0], userIds[2], userIds[3],
6877
+ userIds[0], userIds[3],
6878
+ ],
6879
+ });
6880
+ run_assignment_simulation({ iterations: 10,
6881
+ expectedSelections: [
6882
+ userIds[0], userIds[1], userIds[2], userIds[3],
6883
+ userIds[0], userIds[2], userIds[3],
6884
+ userIds[0], userIds[3],
6885
+ userIds[0],
6886
+ ],
6887
+ });
6888
+ run_assignment_simulation({ iterations: 11,
6889
+ expectedSelections: [
6890
+ userIds[0], userIds[1], userIds[2], userIds[3],
6891
+ userIds[0], userIds[2], userIds[3],
6892
+ userIds[0], userIds[3],
6893
+ userIds[0],
6894
+ userIds[0],
6895
+ ],
6896
+ });
6897
+ run_assignment_simulation({ iterations: 12,
6898
+ expectedSelections: [
6899
+ userIds[0], userIds[1], userIds[2], userIds[3],
6900
+ userIds[0], userIds[2], userIds[3],
6901
+ userIds[0], userIds[3],
6902
+ userIds[0],
6903
+ userIds[0],
6904
+ userIds[0],
6905
+ ],
6906
+ });
6907
+ run_assignment_simulation({ iterations: 13,
6908
+ expectedSelections: [
6909
+ userIds[0], userIds[1], userIds[2], userIds[3],
6910
+ userIds[0], userIds[2], userIds[3],
6911
+ userIds[0], userIds[3],
6912
+ userIds[0],
6913
+ userIds[0],
6914
+ userIds[0], userIds[1],
6915
+ ],
6916
+ });
6917
+ run_assignment_simulation({ iterations: 14,
6918
+ expectedSelections: [
6919
+ userIds[0], userIds[1], userIds[2], userIds[3],
6920
+ userIds[0], userIds[2], userIds[3],
6921
+ userIds[0], userIds[3],
6922
+ userIds[0],
6923
+ userIds[0],
6924
+ userIds[0], userIds[1], userIds[2],
6925
+ ],
6926
+ });
6927
+ run_assignment_simulation({ iterations: 15,
6928
+ expectedSelections: [
6929
+ userIds[0], userIds[1], userIds[2], userIds[3],
6930
+ userIds[0], userIds[2], userIds[3],
6931
+ userIds[0], userIds[3],
6932
+ userIds[0],
6933
+ userIds[0],
6934
+ userIds[0], userIds[1], userIds[2], userIds[3],
6935
+ ],
6936
+ });
6937
+ return [2 /*return*/];
6938
+ }
6939
+ });
6940
+ }); };
6786
6941
  (function () { return __awaiter(void 0, void 0, void 0, function () {
6787
6942
  var err_1, n, _a, _b, _c, _i, returnValidation, t, _d, _e, _f, _g, err_2;
6788
6943
  var _h, _j;
@@ -6795,9 +6950,12 @@ var validate_schema = function () {
6795
6950
  _k.sent();
6796
6951
  _k.label = 2;
6797
6952
  case 2:
6798
- _k.trys.push([2, 39, , 40]);
6799
- return [4 /*yield*/, validate_schema()];
6953
+ _k.trys.push([2, 40, , 41]);
6954
+ return [4 /*yield*/, test_weighted_round_robin()];
6800
6955
  case 3:
6956
+ _k.sent();
6957
+ return [4 /*yield*/, validate_schema()];
6958
+ case 4:
6801
6959
  _k.sent();
6802
6960
  return [4 /*yield*/, Promise.all([
6803
6961
  sdk.authenticate(email, password),
@@ -6808,116 +6966,116 @@ var validate_schema = function () {
6808
6966
  ])
6809
6967
  // console.log(JSON.stringify(await sdk.bulk_load({ load: [{ model: 'users' }]}), null, 2))
6810
6968
  ];
6811
- case 4:
6969
+ case 5:
6812
6970
  _k.sent();
6813
6971
  // console.log(JSON.stringify(await sdk.bulk_load({ load: [{ model: 'users' }]}), null, 2))
6814
6972
  return [4 /*yield*/, async_test("count exists",
6815
6973
  // @ts-ignore
6816
6974
  function () { return sdk.api.endusers.getSome({ returnCount: true }); }, { onResult: function (result) { return typeof result.count === 'number'; } })];
6817
- case 5:
6975
+ case 6:
6818
6976
  // console.log(JSON.stringify(await sdk.bulk_load({ load: [{ model: 'users' }]}), null, 2))
6819
6977
  _k.sent();
6820
6978
  return [4 /*yield*/, async_test("push_to_EHR allows missing addedResponses", function () { return sdk.api.form_responses.push_to_EHR({ id: PLACEHOLDER_ID }); }, { shouldError: true, onError: function (e) { return (e === null || e === void 0 ? void 0 : e.message) === 'Could not find a record for the given id'; } })];
6821
- case 6:
6979
+ case 7:
6822
6980
  _k.sent();
6823
6981
  return [4 /*yield*/, mfa_tests()];
6824
- case 7:
6982
+ case 8:
6825
6983
  _k.sent();
6826
6984
  return [4 /*yield*/, setup_tests()];
6827
- case 8:
6985
+ case 9:
6828
6986
  _k.sent();
6829
6987
  return [4 /*yield*/, multi_tenant_tests()]; // should come right after setup tests
6830
- case 9:
6988
+ case 10:
6831
6989
  _k.sent(); // should come right after setup tests
6832
6990
  return [4 /*yield*/, alternate_phones_tests()];
6833
- case 10:
6834
- _k.sent();
6835
- return [4 /*yield*/, ticket_queue_tests()];
6836
6991
  case 11:
6837
6992
  _k.sent();
6838
- return [4 /*yield*/, no_chained_triggers_tests()];
6993
+ return [4 /*yield*/, ticket_queue_tests()];
6839
6994
  case 12:
6840
6995
  _k.sent();
6841
- return [4 /*yield*/, field_equals_trigger_tests()];
6996
+ return [4 /*yield*/, no_chained_triggers_tests()];
6842
6997
  case 13:
6843
6998
  _k.sent();
6844
- return [4 /*yield*/, test_ticket_automation_assignment_and_optimization()];
6999
+ return [4 /*yield*/, field_equals_trigger_tests()];
6845
7000
  case 14:
6846
7001
  _k.sent();
6847
- return [4 /*yield*/, role_based_access_tests()];
7002
+ return [4 /*yield*/, test_ticket_automation_assignment_and_optimization()];
6848
7003
  case 15:
6849
7004
  _k.sent();
6850
- return [4 /*yield*/, automation_trigger_tests()];
7005
+ return [4 /*yield*/, role_based_access_tests()];
6851
7006
  case 16:
6852
7007
  _k.sent();
6853
- return [4 /*yield*/, enduser_session_tests()];
7008
+ return [4 /*yield*/, automation_trigger_tests()];
6854
7009
  case 17:
6855
7010
  _k.sent();
6856
- return [4 /*yield*/, nextReminderInMS_tests()];
7011
+ return [4 /*yield*/, enduser_session_tests()];
6857
7012
  case 18:
6858
7013
  _k.sent();
6859
- return [4 /*yield*/, search_tests()];
7014
+ return [4 /*yield*/, nextReminderInMS_tests()];
6860
7015
  case 19:
6861
7016
  _k.sent();
6862
- return [4 /*yield*/, wait_for_trigger_tests()];
7017
+ return [4 /*yield*/, search_tests()];
6863
7018
  case 20:
6864
7019
  _k.sent();
6865
- return [4 /*yield*/, pdf_generation()];
7020
+ return [4 /*yield*/, wait_for_trigger_tests()];
6866
7021
  case 21:
6867
7022
  _k.sent();
6868
- return [4 /*yield*/, remove_from_journey_on_incoming_comms_tests()];
7023
+ return [4 /*yield*/, pdf_generation()];
6869
7024
  case 22:
6870
7025
  _k.sent();
6871
- return [4 /*yield*/, rate_limit_tests()];
7026
+ return [4 /*yield*/, remove_from_journey_on_incoming_comms_tests()];
6872
7027
  case 23:
6873
7028
  _k.sent();
6874
- return [4 /*yield*/, merge_enduser_tests()];
7029
+ return [4 /*yield*/, rate_limit_tests()];
6875
7030
  case 24:
6876
7031
  _k.sent();
6877
- return [4 /*yield*/, self_serve_appointment_booking_tests()];
7032
+ return [4 /*yield*/, merge_enduser_tests()];
6878
7033
  case 25:
6879
7034
  _k.sent();
6880
- return [4 /*yield*/, auto_reply_tests()];
7035
+ return [4 /*yield*/, self_serve_appointment_booking_tests()];
6881
7036
  case 26:
6882
7037
  _k.sent();
6883
- return [4 /*yield*/, sub_organization_enduser_tests()];
7038
+ return [4 /*yield*/, auto_reply_tests()];
6884
7039
  case 27:
6885
7040
  _k.sent();
6886
- return [4 /*yield*/, sub_organization_tests()];
7041
+ return [4 /*yield*/, sub_organization_enduser_tests()];
6887
7042
  case 28:
6888
7043
  _k.sent();
6889
- return [4 /*yield*/, filter_by_date_tests()];
7044
+ return [4 /*yield*/, sub_organization_tests()];
6890
7045
  case 29:
6891
7046
  _k.sent();
6892
- return [4 /*yield*/, generate_user_auth_tests()];
7047
+ return [4 /*yield*/, filter_by_date_tests()];
6893
7048
  case 30:
6894
7049
  _k.sent();
6895
- return [4 /*yield*/, generateEnduserAuthTests()];
7050
+ return [4 /*yield*/, generate_user_auth_tests()];
6896
7051
  case 31:
6897
7052
  _k.sent();
6898
- return [4 /*yield*/, public_form_tests()];
7053
+ return [4 /*yield*/, generateEnduserAuthTests()];
6899
7054
  case 32:
6900
7055
  _k.sent();
6901
- return [4 /*yield*/, badInputTests()];
7056
+ return [4 /*yield*/, public_form_tests()];
6902
7057
  case 33:
6903
7058
  _k.sent();
6904
- return [4 /*yield*/, filterTests()];
7059
+ return [4 /*yield*/, badInputTests()];
6905
7060
  case 34:
6906
7061
  _k.sent();
6907
- return [4 /*yield*/, updatesTests()];
7062
+ return [4 /*yield*/, filterTests()];
6908
7063
  case 35:
6909
7064
  _k.sent();
6910
- return [4 /*yield*/, threadKeyTests()];
7065
+ return [4 /*yield*/, updatesTests()];
6911
7066
  case 36:
6912
7067
  _k.sent();
6913
- return [4 /*yield*/, enduserAccessTests()];
7068
+ return [4 /*yield*/, threadKeyTests()];
6914
7069
  case 37:
6915
7070
  _k.sent();
6916
- return [4 /*yield*/, enduser_redaction_tests()];
7071
+ return [4 /*yield*/, enduserAccessTests()];
6917
7072
  case 38:
6918
7073
  _k.sent();
6919
- return [3 /*break*/, 40];
7074
+ return [4 /*yield*/, enduser_redaction_tests()];
6920
7075
  case 39:
7076
+ _k.sent();
7077
+ return [3 /*break*/, 41];
7078
+ case 40:
6921
7079
  err_1 = _k.sent();
6922
7080
  console.error("Failed during custom test");
6923
7081
  if (err_1.message && err_1.info) {
@@ -6927,18 +7085,18 @@ var validate_schema = function () {
6927
7085
  console.error(err_1);
6928
7086
  }
6929
7087
  process.exit(1);
6930
- return [3 /*break*/, 40];
6931
- case 40:
7088
+ return [3 /*break*/, 41];
7089
+ case 41:
6932
7090
  _a = schema;
6933
7091
  _b = [];
6934
7092
  for (_c in _a)
6935
7093
  _b.push(_c);
6936
7094
  _i = 0;
6937
- _k.label = 41;
6938
- case 41:
6939
- if (!(_i < _b.length)) return [3 /*break*/, 44];
7095
+ _k.label = 42;
7096
+ case 42:
7097
+ if (!(_i < _b.length)) return [3 /*break*/, 45];
6940
7098
  _c = _b[_i];
6941
- if (!(_c in _a)) return [3 /*break*/, 43];
7099
+ if (!(_c in _a)) return [3 /*break*/, 44];
6942
7100
  n = _c;
6943
7101
  returnValidation = (_j = (_h = schema[n].customActions) === null || _h === void 0 ? void 0 : _h.create) === null || _j === void 0 ? void 0 : _j.returns;
6944
7102
  return [4 /*yield*/, run_generated_tests({
@@ -6949,41 +7107,41 @@ var validate_schema = function () {
6949
7107
  create: returnValidation // ModelFields<ClientModel>,
6950
7108
  }
6951
7109
  })];
6952
- case 42:
6953
- _k.sent();
6954
- _k.label = 43;
6955
7110
  case 43:
6956
- _i++;
6957
- return [3 /*break*/, 41];
7111
+ _k.sent();
7112
+ _k.label = 44;
6958
7113
  case 44:
7114
+ _i++;
7115
+ return [3 /*break*/, 42];
7116
+ case 45:
6959
7117
  _d = tests;
6960
7118
  _e = [];
6961
7119
  for (_f in _d)
6962
7120
  _e.push(_f);
6963
7121
  _g = 0;
6964
- _k.label = 45;
6965
- case 45:
6966
- if (!(_g < _e.length)) return [3 /*break*/, 50];
6967
- _f = _e[_g];
6968
- if (!(_f in _d)) return [3 /*break*/, 49];
6969
- t = _f;
6970
7122
  _k.label = 46;
6971
7123
  case 46:
6972
- _k.trys.push([46, 48, , 49]);
6973
- return [4 /*yield*/, tests[t]()];
7124
+ if (!(_g < _e.length)) return [3 /*break*/, 51];
7125
+ _f = _e[_g];
7126
+ if (!(_f in _d)) return [3 /*break*/, 50];
7127
+ t = _f;
7128
+ _k.label = 47;
6974
7129
  case 47:
6975
- _k.sent();
6976
- return [3 /*break*/, 49];
7130
+ _k.trys.push([47, 49, , 50]);
7131
+ return [4 /*yield*/, tests[t]()];
6977
7132
  case 48:
7133
+ _k.sent();
7134
+ return [3 /*break*/, 50];
7135
+ case 49:
6978
7136
  err_2 = _k.sent();
6979
7137
  console.error("Error running test:");
6980
7138
  console.error(err_2);
6981
7139
  process.exit(1);
6982
- return [3 /*break*/, 49];
6983
- case 49:
6984
- _g++;
6985
- return [3 /*break*/, 45];
7140
+ return [3 /*break*/, 50];
6986
7141
  case 50:
7142
+ _g++;
7143
+ return [3 /*break*/, 46];
7144
+ case 51:
6987
7145
  process.exit();
6988
7146
  return [2 /*return*/];
6989
7147
  }