@tellescope/sdk 1.38.3 → 1.38.4

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.
@@ -1080,10 +1080,10 @@ const sms_tests = async (queries=sdk.api.sms_messages) => {
1080
1080
  () => queries.createOne(testSMS),
1081
1081
  { onResult: t => !!t }
1082
1082
  )
1083
- testSMS.message = "(Multi-Send)"
1083
+ testSMS.message = "(Multi-Send)" // sending 3 or more will exceed rate limit of 3-per-3 seconds
1084
1084
  await async_test(
1085
1085
  `send-sms (multiple)`,
1086
- () => queries.createSome([ testSMS, testSMS, testSMS ]),
1086
+ () => queries.createSome([ testSMS, testSMS ]),
1087
1087
  { onResult: t => !!t }
1088
1088
  )
1089
1089
 
@@ -4223,6 +4223,107 @@ const wait_for_trigger_tests = async () => {
4223
4223
  // double-check that wait for trigger step triggers were deleted
4224
4224
  }
4225
4225
 
4226
+
4227
+ const handleRateLimitError = { shouldError: true, onError: (e: { message: string }) => e.message === 'Rate limit exceeded'}
4228
+ const rate_limit_tests = async () => {
4229
+ log_header("Rate Limits")
4230
+
4231
+ const [e1, e2] = (await sdk.api.endusers.createSome([
4232
+ { fname: '1', email: 'e1@tellescope.com', phone: '+15555555555' },
4233
+ { fname: '2', email: 'e2@tellescope.com', phone: '+15555555555' },
4234
+ ])).created
4235
+
4236
+ await async_test(
4237
+ "Same template email rate limit 1-per-minute",
4238
+ () => sdk.api.emails.createSome([
4239
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', templateId: PLACEHOLDER_ID },
4240
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', templateId: PLACEHOLDER_ID },
4241
+ ]),
4242
+ handleRateLimitError
4243
+ )
4244
+
4245
+ // these should work, as 1 each is safe
4246
+ const [email1, email2] = (await sdk.api.emails.createSome([
4247
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', templateId: PLACEHOLDER_ID },
4248
+ { logOnly: true, enduserId: e2.id, subject: 'ratelimit', textContent: 'rate limit', templateId: PLACEHOLDER_ID },
4249
+ ])).created
4250
+ // already has 1 created
4251
+ await async_test(
4252
+ "Same enduser rate limit 5 per 5 seconds",
4253
+ () => sdk.api.emails.createSome([
4254
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', },
4255
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', },
4256
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', },
4257
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', },
4258
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit' },
4259
+ ]),
4260
+ handleRateLimitError
4261
+ )
4262
+
4263
+ await wait(undefined, 2500) // give it some time before trying again, to ensure still blocked after 2.5 < 60 seconds
4264
+ await async_test(
4265
+ "Same template email rate limit 1-per-minute after creating",
4266
+ () => sdk.api.emails.createOne({
4267
+ logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit', templateId: PLACEHOLDER_ID
4268
+ }),
4269
+ handleRateLimitError
4270
+ )
4271
+
4272
+
4273
+ await async_test(
4274
+ "Same template sms rate limit 1-per-minute",
4275
+ () => sdk.api.sms_messages.createSome([
4276
+ { logOnly: true, enduserId: e1.id, templateId: PLACEHOLDER_ID, message: 'hi' },
4277
+ { logOnly: true, enduserId: e1.id, templateId: PLACEHOLDER_ID, message: 'hi' },
4278
+ ]),
4279
+ handleRateLimitError
4280
+ )
4281
+
4282
+ // these should work, as 1 each is safe
4283
+ const [sms1, sms2] = (await sdk.api.sms_messages.createSome([
4284
+ { logOnly: true, enduserId: e1.id, templateId: PLACEHOLDER_ID, message: 'hi' },
4285
+ { logOnly: true, enduserId: e2.id, templateId: PLACEHOLDER_ID, message: 'hi' },
4286
+ ])).created
4287
+ // already has 1 created, so 3 new should error (4 > 3)
4288
+ await async_test(
4289
+ "Same enduser sms rate limit 3 per 3 seconds",
4290
+ () => sdk.api.sms_messages.createSome([
4291
+ { logOnly: true, enduserId: e1.id, message: 'hi' },
4292
+ { logOnly: true, enduserId: e1.id, message: 'hi' },
4293
+ { logOnly: true, enduserId: e1.id, message: 'hi' },
4294
+ ]),
4295
+ handleRateLimitError
4296
+ )
4297
+
4298
+ await wait(undefined, 2500) // give it some time before trying again, to ensure still blocked after 2.5 < 60 seconds
4299
+ await async_test(
4300
+ "Same template sms rate limit 1-per-minute after creating",
4301
+ () => sdk.api.sms_messages.createOne({
4302
+ logOnly: true, enduserId: e2.id, templateId: PLACEHOLDER_ID, message: 'hi'
4303
+ }),
4304
+ handleRateLimitError
4305
+ )
4306
+
4307
+ // these should work, as they do not have the same template
4308
+ const [email3, email4, email5] = (await sdk.api.emails.createSome([
4309
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit' },
4310
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit' },
4311
+ { logOnly: true, enduserId: e1.id, subject: 'ratelimit', textContent: 'rate limit' },
4312
+ ])).created
4313
+
4314
+ await Promise.all([
4315
+ sdk.api.endusers.deleteOne(e1.id),
4316
+ sdk.api.endusers.deleteOne(e2.id),
4317
+ sdk.api.emails.deleteOne(email1.id),
4318
+ sdk.api.emails.deleteOne(email2.id),
4319
+ sdk.api.emails.deleteOne(email3.id),
4320
+ sdk.api.emails.deleteOne(email4.id),
4321
+ sdk.api.emails.deleteOne(email5.id),
4322
+ sdk.api.sms_messages.deleteOne(sms1.id),
4323
+ sdk.api.sms_messages.deleteOne(sms2.id),
4324
+ ])
4325
+ }
4326
+
4226
4327
  const NO_TEST = () => {}
4227
4328
  const tests: { [K in keyof ClientModelForName]: () => void } = {
4228
4329
  phone_trees: NO_TEST,
@@ -4299,6 +4400,7 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
4299
4400
  ])
4300
4401
  await setup_tests()
4301
4402
  await multi_tenant_tests() // should come right after setup tests
4403
+ await rate_limit_tests()
4302
4404
  await role_based_access_tests()
4303
4405
  await wait_for_trigger_tests()
4304
4406
  await merge_enduser_tests()