mpt-extension-sdk 4.0.6__py3-none-any.whl → 4.1.0__py3-none-any.whl

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.
@@ -1,3 +1,7 @@
1
+ from enum import Enum, unique
2
+
3
+ from django.conf import settings
4
+
1
5
  EVENT_TYPES = "orders"
2
6
  SECURITY_ALGORITHM = "HS256"
3
7
  USER_AGENT = "swo-extensions/1.0"
@@ -5,3 +9,6 @@ CONSUME_EVENTS_HELP_TEXT = "Consume events from the MPT platform"
5
9
  DEFAULT_APP_CONFIG_GROUP = "swo.mpt.sdk"
6
10
  DEFAULT_APP_CONFIG_NAME = "app_config"
7
11
  DJANGO_SETTINGS_MODULE = "mpt_extension_sdk.runtime.djapp.conf.default"
12
+
13
+
14
+ NotifyCategories = unique(Enum("NotifyCategories", settings.MPT_NOTIFY_CATEGORIES))
@@ -1,9 +1,12 @@
1
1
  import logging
2
2
  from datetime import date
3
3
  from functools import cache
4
+ from itertools import batched
4
5
 
5
6
  from django.conf import settings
6
7
 
8
+ from mpt_extension_sdk.constants import NotifyCategories
9
+ from mpt_extension_sdk.mpt_http.base import MPTClient
7
10
  from mpt_extension_sdk.mpt_http.wrap_http_error import wrap_mpt_http_error
8
11
 
9
12
  logger = logging.getLogger(__name__)
@@ -16,10 +19,9 @@ def _has_more_pages(page):
16
19
  return pagination["total"] > pagination["limit"] + pagination["offset"]
17
20
 
18
21
 
19
- def _paginated(mpt_client, url):
22
+ def _paginated(mpt_client, url, limit=10):
20
23
  items = []
21
24
  page = None
22
- limit = 10
23
25
  offset = 0
24
26
  while _has_more_pages(page):
25
27
  response = mpt_client.get(f"{url}&limit={limit}&offset={offset}")
@@ -374,3 +376,56 @@ def get_buyer(mpt_client, buyer_id):
374
376
  response = mpt_client.get(f"/accounts/buyers/{buyer_id}")
375
377
  response.raise_for_status()
376
378
  return response.json()
379
+
380
+
381
+ @wrap_mpt_http_error
382
+ def notify(
383
+ mpt_client: MPTClient,
384
+ category_id: NotifyCategories,
385
+ account_id: str,
386
+ buyer_id: str,
387
+ subject: str,
388
+ message_body: str,
389
+ limit: int = 1000,
390
+ ):
391
+ """
392
+ Sends notifications to multiple recipients in batches for a specific buyer and
393
+ category through the MPTClient service. The function retrieves recipients,
394
+ groups them into manageable batches, and sends notifications using the provided
395
+ message details.
396
+
397
+ Args:
398
+ mpt_client (MPTClient): Client object for interacting with MPT service.
399
+ category_id (NotifyCategories): Identifier for the category of recipients or messages.
400
+ account_id (str): Identifier for the associated account.
401
+ buyer_id (str): Identifier for the buyer related to the notification.
402
+ subject (str): Subject/title of the notification to be sent.
403
+ message_body (str): Content/body of the notification message.
404
+ limit (int): Maximum number of recipients to process per batch. Defaults
405
+ to 1000.
406
+
407
+ Returns:
408
+ None
409
+ """
410
+ recipients = _paginated(
411
+ mpt_client,
412
+ url=(
413
+ f"notifications/accounts/{account_id}/categories/{category_id}/contacts?"
414
+ f"select=id,-email,-name,-status,-user&"
415
+ f"filter(group.buyers.id,{buyer_id})"
416
+ ),
417
+ limit=limit,
418
+ )
419
+
420
+ for contacts in batched(recipients, limit):
421
+ response = mpt_client.post(
422
+ "notifications/batches",
423
+ json={
424
+ "category": {"id": category_id},
425
+ "subject": subject,
426
+ "body": message_body,
427
+ "contacts": contacts,
428
+ "buyer": {"id": buyer_id},
429
+ },
430
+ )
431
+ response.raise_for_status()
@@ -10,6 +10,7 @@ For the full list of settings and their values, see
10
10
  https://docs.djangoproject.com/en/4.2/ref/settings/
11
11
  """
12
12
 
13
+ import json
13
14
  import os
14
15
  from pathlib import Path
15
16
 
@@ -213,6 +214,11 @@ MPT_ORDERS_API_POLLING_INTERVAL_SECS = int(
213
214
  os.getenv("MPT_ORDERS_API_POLLING_INTERVAL_SECS", "120")
214
215
  )
215
216
 
217
+ # TODO: Should be synced with the initializer.py::initialize function
218
+ MPT_NOTIFY_CATEGORIES = json.loads(
219
+ os.getenv("MPT_NOTIFY_CATEGORIES", '{"ORDERS": "NTC-0000-0006"}')
220
+ )
221
+
216
222
  EXTENSION_CONFIG = {
217
223
  "DUE_DATE_DAYS": "30",
218
224
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mpt-extension-sdk
3
- Version: 4.0.6
3
+ Version: 4.1.0
4
4
  Summary: Extensions SDK for SoftwareONE Marketplace Platform
5
5
  License: Apache-2.0
6
6
  Author: SoftwareOne AG
@@ -1,6 +1,6 @@
1
1
  mpt_extension_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  mpt_extension_sdk/airtable/wrap_http_error.py,sha256=Shiy4uwpdpgkevooLjhpe1grhgJRj7cV6lUMMCQKogc,1263
3
- mpt_extension_sdk/constants.py,sha256=4LyR-sUD9-V226jG4cRXKqXKeqjwAj1euL4XRURSfQw,304
3
+ mpt_extension_sdk/constants.py,sha256=NhY_PNqZcfZ7vNRd0O5Vc6zOmpN5y13eChvYZhRpJkQ,455
4
4
  mpt_extension_sdk/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  mpt_extension_sdk/core/events/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  mpt_extension_sdk/core/events/dataclasses.py,sha256=wBxjEmjzIwpSH4trpCQKYQPNzONBAgr8eQzTr3ulzkA,469
@@ -15,7 +15,7 @@ mpt_extension_sdk/key_vault/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
15
15
  mpt_extension_sdk/key_vault/base.py,sha256=0aXH5c5n9-rUCwmBVY_HtIFUVB6JUC0137Duyh-basw,3321
16
16
  mpt_extension_sdk/mpt_http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  mpt_extension_sdk/mpt_http/base.py,sha256=3qgo9BW-uTRAbex26urMvLZU0fwnYnBprDRIJCHvTOk,1284
18
- mpt_extension_sdk/mpt_http/mpt.py,sha256=c00ouqvK6temaVVND4XNVbKAeJ_7epMLL6BEBBB6WAs,10572
18
+ mpt_extension_sdk/mpt_http/mpt.py,sha256=07XH5V410_oJMArJOXSa2FafKH3vDew-1HoANVkN5qw,12488
19
19
  mpt_extension_sdk/mpt_http/utils.py,sha256=3wJTT84CXYGjZw6FksNDX8tIHijkL3Wcmld9r6Iz0xc,95
20
20
  mpt_extension_sdk/mpt_http/wrap_http_error.py,sha256=j8K6Ddx7NiM-FPRMQi25vuULAW8LXxzZ4EwuIJufxis,1801
21
21
  mpt_extension_sdk/runtime/__init__.py,sha256=PQSAz9qvXHbxrn4KvuXSHB8y-A4Jpgbm6ZV-wPiNPyw,194
@@ -25,7 +25,7 @@ mpt_extension_sdk/runtime/commands/run.py,sha256=1Qrqr2Hq1J8JvXtmEdgUNU9u3JLd_92
25
25
  mpt_extension_sdk/runtime/djapp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  mpt_extension_sdk/runtime/djapp/apps.py,sha256=YA1G5HaRqFBS-0DfYQuFpMgzUCYpu5T8x5LEC6MwI_M,1398
27
27
  mpt_extension_sdk/runtime/djapp/conf/__init__.py,sha256=_sHo76rGeXSTH8bW3pacyGFfNYSln8oLRwOSstYOmco,350
28
- mpt_extension_sdk/runtime/djapp/conf/default.py,sha256=qlgOaX7hcAyt52lAZD5JufQq898yWnWR-qUzxhycXjk,6126
28
+ mpt_extension_sdk/runtime/djapp/conf/default.py,sha256=z__q7OW12YBPE0MFv5zsq0hPf2z3-x1Mmimms6LBfU8,6317
29
29
  mpt_extension_sdk/runtime/djapp/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  mpt_extension_sdk/runtime/djapp/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  mpt_extension_sdk/runtime/djapp/management/commands/consume_events.py,sha256=r5aW4Sratsmnu6ccI7kHYZMBGL8P697wKts5iZPoaHc,1080
@@ -40,8 +40,8 @@ mpt_extension_sdk/runtime/master.py,sha256=oBI3WHpf2YkTRsRyT1SFIyvCM7gGQpbtXvI1l
40
40
  mpt_extension_sdk/runtime/swoext.py,sha256=LS0YZXwQsHDaYjalDGfYQi5cAL3aKQhphf3chrNmNBk,1665
41
41
  mpt_extension_sdk/runtime/utils.py,sha256=ZnRWIBwYzOerx30KFmBXLUe19qzwE4JFNkNMGVqjuyk,3365
42
42
  mpt_extension_sdk/runtime/workers.py,sha256=k25jFlh-NdHVqeMV2AgoC6IHIlbRHcDoRB5xqWwMPFg,2411
43
- mpt_extension_sdk-4.0.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
- mpt_extension_sdk-4.0.6.dist-info/METADATA,sha256=mqCgiEGwkxt89Rra5o9q0o3qBO8ZVPT8kRs3PtqdUGQ,1666
45
- mpt_extension_sdk-4.0.6.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
- mpt_extension_sdk-4.0.6.dist-info/entry_points.txt,sha256=8uZQihFseK4Kp5XWHl9EDYneg-CLS8BFO-ygp0h34nc,143
47
- mpt_extension_sdk-4.0.6.dist-info/RECORD,,
43
+ mpt_extension_sdk-4.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
+ mpt_extension_sdk-4.1.0.dist-info/METADATA,sha256=dBZ2ptasTttKoIKvw1oRUtB8N1b06kDDXcW4wBCd1H4,1666
45
+ mpt_extension_sdk-4.1.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
+ mpt_extension_sdk-4.1.0.dist-info/entry_points.txt,sha256=8uZQihFseK4Kp5XWHl9EDYneg-CLS8BFO-ygp0h34nc,143
47
+ mpt_extension_sdk-4.1.0.dist-info/RECORD,,