@primitivedotdev/sdk 0.19.0 → 0.21.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.
@@ -617,15 +617,20 @@ var sdk_gen_exports = /* @__PURE__ */ __exportAll({
617
617
  cliLogout: () => cliLogout,
618
618
  createEndpoint: () => createEndpoint,
619
619
  createFilter: () => createFilter,
620
+ createFunction: () => createFunction,
621
+ createFunctionSecret: () => createFunctionSecret,
620
622
  deleteDomain: () => deleteDomain,
621
623
  deleteEmail: () => deleteEmail,
622
624
  deleteEndpoint: () => deleteEndpoint,
623
625
  deleteFilter: () => deleteFilter,
626
+ deleteFunction: () => deleteFunction,
627
+ deleteFunctionSecret: () => deleteFunctionSecret,
624
628
  discardEmailContent: () => discardEmailContent,
625
629
  downloadAttachments: () => downloadAttachments,
626
630
  downloadRawEmail: () => downloadRawEmail,
627
631
  getAccount: () => getAccount,
628
632
  getEmail: () => getEmail,
633
+ getFunction: () => getFunction,
629
634
  getSendPermissions: () => getSendPermissions,
630
635
  getSentEmail: () => getSentEmail,
631
636
  getStorageStats: () => getStorageStats,
@@ -635,19 +640,25 @@ var sdk_gen_exports = /* @__PURE__ */ __exportAll({
635
640
  listEmails: () => listEmails,
636
641
  listEndpoints: () => listEndpoints,
637
642
  listFilters: () => listFilters,
643
+ listFunctionSecrets: () => listFunctionSecrets,
644
+ listFunctions: () => listFunctions,
638
645
  listSentEmails: () => listSentEmails,
639
646
  pollCliLogin: () => pollCliLogin,
640
647
  replayDelivery: () => replayDelivery,
641
648
  replayEmailWebhooks: () => replayEmailWebhooks,
642
649
  replyToEmail: () => replyToEmail,
643
650
  rotateWebhookSecret: () => rotateWebhookSecret,
651
+ searchEmails: () => searchEmails,
644
652
  sendEmail: () => sendEmail,
653
+ setFunctionSecret: () => setFunctionSecret,
645
654
  startCliLogin: () => startCliLogin,
646
655
  testEndpoint: () => testEndpoint,
656
+ testFunction: () => testFunction,
647
657
  updateAccount: () => updateAccount,
648
658
  updateDomain: () => updateDomain,
649
659
  updateEndpoint: () => updateEndpoint,
650
660
  updateFilter: () => updateFilter,
661
+ updateFunction: () => updateFunction,
651
662
  verifyDomain: () => verifyDomain
652
663
  });
653
664
  /**
@@ -898,6 +909,30 @@ const listEmails = (options) => (options?.client ?? client$1).get({
898
909
  ...options
899
910
  });
900
911
  /**
912
+ * Search inbound emails
913
+ *
914
+ * Searches inbound emails with structured filters and optional
915
+ * full-text matching across parsed email fields. This endpoint is
916
+ * optimized for filtered inbox views and CLI polling workflows:
917
+ * callers that only need new accepted mail can pass
918
+ * `sort=received_at_asc`, `snippet=false`, `include_facets=false`,
919
+ * and a `date_from` timestamp.
920
+ *
921
+ * `q`, `subject`, and `body` use the same English full-text index
922
+ * as the web inbox search. Structured filters such as `from`, `to`,
923
+ * `domain_id`, status, attachment presence, and spam score bounds
924
+ * are combined with the text query.
925
+ *
926
+ */
927
+ const searchEmails = (options) => (options?.client ?? client$1).get({
928
+ security: [{
929
+ scheme: "bearer",
930
+ type: "http"
931
+ }],
932
+ url: "/emails/search",
933
+ ...options
934
+ });
935
+ /**
901
936
  * Delete an email
902
937
  */
903
938
  const deleteEmail = (options) => (options.client ?? client$1).delete({
@@ -1297,6 +1332,15 @@ const getSendPermissions = (options) => (options?.client ?? client$1).get({
1297
1332
  * the request returns once the relay accepts the message for delivery.
1298
1333
  * Set `wait: true` to wait for the first downstream SMTP delivery outcome.
1299
1334
  *
1335
+ * **Host routing.** /send-mail is served by the attachments-
1336
+ * supporting host (`https://api.primitive.dev/v1`) so the
1337
+ * request body can carry inline attachments up to ~30 MiB raw.
1338
+ * The primary host (`https://www.primitive.dev/api/v1`) also
1339
+ * accepts /send-mail for attachment-free sends; sends WITH
1340
+ * attachments to the primary host return 413
1341
+ * `attachments_unsupported_on_this_endpoint`. The typed SDKs
1342
+ * route /send-mail to the attachments host automatically.
1343
+ *
1300
1344
  */
1301
1345
  const sendEmail = (options) => (options.client ?? client$1).post({
1302
1346
  security: [{
@@ -1359,9 +1403,245 @@ const getSentEmail = (options) => (options.client ?? client$1).get({
1359
1403
  url: "/sent-emails/{id}",
1360
1404
  ...options
1361
1405
  });
1406
+ /**
1407
+ * List functions
1408
+ *
1409
+ * Returns every active (non-deleted) function in the org, newest
1410
+ * first. Each entry carries the deploy status and the gateway URL
1411
+ * that the platform's webhook delivery loop posts to. To inspect
1412
+ * the source code or deploy errors, use `GET /functions/{id}`.
1413
+ *
1414
+ */
1415
+ const listFunctions = (options) => (options?.client ?? client$1).get({
1416
+ security: [{
1417
+ scheme: "bearer",
1418
+ type: "http"
1419
+ }],
1420
+ url: "/functions",
1421
+ ...options
1422
+ });
1423
+ /**
1424
+ * Deploy a function
1425
+ *
1426
+ * Creates and deploys a new function. The handler must be a single
1427
+ * ESM module that exports a default async function receiving the
1428
+ * `email.received` event (see the Webhook payload section for the
1429
+ * full schema). Code is bundled before being uploaded; ship a
1430
+ * single self-contained file rather than relying on external
1431
+ * imports.
1432
+ *
1433
+ * **Code limits.** `code` is capped at 1 MiB UTF-8. `sourceMap`
1434
+ * (optional) is capped at 5 MiB UTF-8 and is stored only on the
1435
+ * edge runtime side; it is not persisted in Primitive's database.
1436
+ *
1437
+ * **Auto-wiring.** On successful deploy, Primitive automatically
1438
+ * creates a webhook endpoint that delivers inbound mail to the
1439
+ * function. There is nothing to configure on the Endpoints API
1440
+ * for this to work; the gateway URL returned here is for
1441
+ * reference only and is not directly callable from outside.
1442
+ *
1443
+ * **Secrets.** New functions ship with the managed secrets
1444
+ * (`PRIMITIVE_WEBHOOK_SECRET`, `PRIMITIVE_API_KEY`) already
1445
+ * bound. Add user-set secrets via
1446
+ * `POST /functions/{id}/secrets`; secret writes only land in the
1447
+ * running handler on the next redeploy.
1448
+ *
1449
+ */
1450
+ const createFunction = (options) => (options.client ?? client$1).post({
1451
+ security: [{
1452
+ scheme: "bearer",
1453
+ type: "http"
1454
+ }],
1455
+ url: "/functions",
1456
+ ...options,
1457
+ headers: {
1458
+ "Content-Type": "application/json",
1459
+ ...options.headers
1460
+ }
1461
+ });
1462
+ /**
1463
+ * Delete a function
1464
+ *
1465
+ * Soft-deletes the function row, removes the script from the edge
1466
+ * runtime, and deactivates the auto-wired webhook endpoint so no
1467
+ * further inbound mail is delivered. Past deploy history,
1468
+ * invocations, and logs are retained.
1469
+ *
1470
+ * Returns 502 if the runtime delete fails partway; the function
1471
+ * row stays in place and the call is safe to retry until it
1472
+ * succeeds.
1473
+ *
1474
+ */
1475
+ const deleteFunction = (options) => (options.client ?? client$1).delete({
1476
+ security: [{
1477
+ scheme: "bearer",
1478
+ type: "http"
1479
+ }],
1480
+ url: "/functions/{id}",
1481
+ ...options
1482
+ });
1483
+ /**
1484
+ * Get a function
1485
+ *
1486
+ * Returns the full record for a function, including its current
1487
+ * source code and the deploy status / error from the most recent
1488
+ * deploy attempt.
1489
+ *
1490
+ */
1491
+ const getFunction = (options) => (options.client ?? client$1).get({
1492
+ security: [{
1493
+ scheme: "bearer",
1494
+ type: "http"
1495
+ }],
1496
+ url: "/functions/{id}",
1497
+ ...options
1498
+ });
1499
+ /**
1500
+ * Update and redeploy a function
1501
+ *
1502
+ * Replaces the function's source code with the body's `code` and
1503
+ * triggers a redeploy. Same size limits as `POST /functions`.
1504
+ * Use this verb to push secret writes into the running handler:
1505
+ * passing the same `code` re-runs the deploy and refreshes the
1506
+ * binding set with the latest values from the secrets table.
1507
+ *
1508
+ * On a 502 deploy failure, the previously-deployed code stays
1509
+ * live; the runtime never serves a half-built bundle. The
1510
+ * `deploy_error` field on the returned record carries the error
1511
+ * that came back from the runtime so you can surface it to users
1512
+ * without polling.
1513
+ *
1514
+ */
1515
+ const updateFunction = (options) => (options.client ?? client$1).put({
1516
+ security: [{
1517
+ scheme: "bearer",
1518
+ type: "http"
1519
+ }],
1520
+ url: "/functions/{id}",
1521
+ ...options,
1522
+ headers: {
1523
+ "Content-Type": "application/json",
1524
+ ...options.headers
1525
+ }
1526
+ });
1527
+ /**
1528
+ * Send a test invocation
1529
+ *
1530
+ * Sends a real test email from a Primitive-controlled sender to a
1531
+ * synthetic local-part on one of the org's verified inbound
1532
+ * domains. The function fires through the normal MX delivery
1533
+ * path, so reply / send-mail calls from inside the handler
1534
+ * against the inbound's `email.id` work the same as in
1535
+ * production. Returns immediately after the send is queued; the
1536
+ * invocation appears on the function's invocations list within a
1537
+ * few seconds.
1538
+ *
1539
+ * Requires that the function is currently `deployed`. Returns 422
1540
+ * if the function is in `pending` or `failed` state, or if the
1541
+ * org has no verified inbound domain to receive the test mail.
1542
+ *
1543
+ */
1544
+ const testFunction = (options) => (options.client ?? client$1).post({
1545
+ security: [{
1546
+ scheme: "bearer",
1547
+ type: "http"
1548
+ }],
1549
+ url: "/functions/{id}/test",
1550
+ ...options
1551
+ });
1552
+ /**
1553
+ * List a function's secrets
1554
+ *
1555
+ * Returns metadata for every secret bound to the function, with
1556
+ * managed entries (provisioned by Primitive) listed first and
1557
+ * user-set entries listed alphabetically after. **Values are
1558
+ * never returned.** Secret writes are write-only.
1559
+ *
1560
+ * Managed entries (e.g. `PRIMITIVE_WEBHOOK_SECRET`,
1561
+ * `PRIMITIVE_API_KEY`) carry a `description` instead of
1562
+ * `created_at` / `updated_at`. They cannot be created, updated,
1563
+ * or deleted via this API.
1564
+ *
1565
+ */
1566
+ const listFunctionSecrets = (options) => (options.client ?? client$1).get({
1567
+ security: [{
1568
+ scheme: "bearer",
1569
+ type: "http"
1570
+ }],
1571
+ url: "/functions/{id}/secrets",
1572
+ ...options
1573
+ });
1574
+ /**
1575
+ * Create or update a secret
1576
+ *
1577
+ * Idempotent insert-or-update keyed on `(function_id, key)`.
1578
+ * Returns 201 the first time the key is set, 200 on subsequent
1579
+ * updates. Values are encrypted at rest and only become visible
1580
+ * to the running handler on the next deploy (`PUT /functions/{id}`
1581
+ * with the existing code is sufficient to refresh bindings).
1582
+ *
1583
+ * Keys must match `^[A-Z_][A-Z0-9_]*$` (uppercase letters,
1584
+ * digits, underscores; first character is a letter or
1585
+ * underscore). Values are at most 4096 UTF-8 bytes. System-
1586
+ * managed keys are reserved and rejected.
1587
+ *
1588
+ */
1589
+ const createFunctionSecret = (options) => (options.client ?? client$1).post({
1590
+ security: [{
1591
+ scheme: "bearer",
1592
+ type: "http"
1593
+ }],
1594
+ url: "/functions/{id}/secrets",
1595
+ ...options,
1596
+ headers: {
1597
+ "Content-Type": "application/json",
1598
+ ...options.headers
1599
+ }
1600
+ });
1601
+ /**
1602
+ * Delete a secret
1603
+ *
1604
+ * Removes the secret. The binding stays live in the running
1605
+ * handler until the next deploy refreshes the binding set
1606
+ * (`PUT /functions/{id}` with the existing code is sufficient).
1607
+ * Returns 404 if the key did not exist. Managed system keys
1608
+ * cannot be deleted.
1609
+ *
1610
+ */
1611
+ const deleteFunctionSecret = (options) => (options.client ?? client$1).delete({
1612
+ security: [{
1613
+ scheme: "bearer",
1614
+ type: "http"
1615
+ }],
1616
+ url: "/functions/{id}/secrets/{key}",
1617
+ ...options
1618
+ });
1619
+ /**
1620
+ * Set a secret by key
1621
+ *
1622
+ * Path-keyed companion to `POST /functions/{id}/secrets`.
1623
+ * Idempotent: returns 201 the first time the key is set, 200 on
1624
+ * subsequent updates. Same validation rules and same write-only
1625
+ * guarantees as the POST verb; the new value lands in the running
1626
+ * handler on the next deploy.
1627
+ *
1628
+ */
1629
+ const setFunctionSecret = (options) => (options.client ?? client$1).put({
1630
+ security: [{
1631
+ scheme: "bearer",
1632
+ type: "http"
1633
+ }],
1634
+ url: "/functions/{id}/secrets/{key}",
1635
+ ...options,
1636
+ headers: {
1637
+ "Content-Type": "application/json",
1638
+ ...options.headers
1639
+ }
1640
+ });
1362
1641
  //#endregion
1363
1642
  //#region src/api/index.ts
1364
- const DEFAULT_BASE_URL = "https://www.primitive.dev/api/v1";
1643
+ const DEFAULT_API_BASE_URL_1 = "https://www.primitive.dev/api/v1";
1644
+ const DEFAULT_API_BASE_URL_2 = "https://api.primitive.dev/v1";
1365
1645
  const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1366
1646
  const MAX_THREAD_REFERENCES = 100;
1367
1647
  const MAX_THREAD_HEADER_BYTES = 8 * 1024;
@@ -1467,13 +1747,35 @@ function parseRetryAfterHeader(response) {
1467
1747
  return Number.isFinite(seconds) ? seconds : void 0;
1468
1748
  }
1469
1749
  var PrimitiveApiClient = class {
1750
+ /**
1751
+ * Generated client targeting the primary API host (apiBaseUrl1). Use
1752
+ * this when passing `client: ...` to a generated operation function
1753
+ * for every endpoint EXCEPT /send-mail. The hand-written
1754
+ * PrimitiveClient.send / .reply / .forward methods on the subclass
1755
+ * route /send-mail to the host-2 client internally.
1756
+ */
1470
1757
  client;
1758
+ /**
1759
+ * @internal Generated client targeting the attachments-supporting
1760
+ * send host (apiBaseUrl2). Used by PrimitiveClient.send() under the
1761
+ * hood. Exposed for the CLI's hand-rolled send command, which calls
1762
+ * the generated sendEmail directly; not part of the publicly-
1763
+ * documented SDK surface. Customer code should call .send() on the
1764
+ * subclass instead.
1765
+ */
1766
+ _sendClient;
1471
1767
  constructor(options = {}) {
1472
- const { apiKey, auth, baseUrl = DEFAULT_BASE_URL, ...config } = options;
1768
+ const { apiKey, auth, apiBaseUrl1 = DEFAULT_API_BASE_URL_1, apiBaseUrl2 = DEFAULT_API_BASE_URL_2, ...config } = options;
1769
+ const resolvedAuth = auth ?? createDefaultAuth(apiKey);
1473
1770
  this.client = createClient(createConfig({
1474
1771
  ...config,
1475
- auth: auth ?? createDefaultAuth(apiKey),
1476
- baseUrl
1772
+ auth: resolvedAuth,
1773
+ baseUrl: apiBaseUrl1
1774
+ }));
1775
+ this._sendClient = createClient(createConfig({
1776
+ ...config,
1777
+ auth: resolvedAuth,
1778
+ baseUrl: apiBaseUrl2
1477
1779
  }));
1478
1780
  }
1479
1781
  getConfig() {
@@ -1513,7 +1815,7 @@ var PrimitiveClient = class extends PrimitiveApiClient {
1513
1815
  ...input.waitTimeoutMs !== void 0 ? { wait_timeout_ms: input.waitTimeoutMs } : {}
1514
1816
  },
1515
1817
  ...resolveRequestOptions(options),
1516
- client: this.client,
1818
+ client: this._sendClient,
1517
1819
  responseStyle: "fields"
1518
1820
  }));
1519
1821
  }
@@ -1625,4 +1927,4 @@ function client(options = {}) {
1625
1927
  }
1626
1928
  const operations = sdk_gen_exports;
1627
1929
  //#endregion
1628
- export { listFilters as A, updateAccount as B, getSentEmail as C, listDomains as D, listDeliveries as E, replyToEmail as F, updateEndpoint as H, rotateWebhookSecret as I, sendEmail as L, pollCliLogin as M, replayDelivery as N, listEmails as O, replayEmailWebhooks as P, startCliLogin as R, getSendPermissions as S, getWebhookSecret as T, updateFilter as U, updateDomain as V, verifyDomain as W, discardEmailContent as _, client as a, getAccount as b, operations as c, createEndpoint as d, createFilter as f, deleteFilter as g, deleteEndpoint as h, PrimitiveClient as i, listSentEmails as j, listEndpoints as k, addDomain as l, deleteEmail as m, PrimitiveApiClient as n, createPrimitiveApiClient as o, deleteDomain as p, PrimitiveApiError as r, createPrimitiveClient as s, DEFAULT_BASE_URL as t, cliLogout as u, downloadAttachments as v, getStorageStats as w, getEmail as x, downloadRawEmail as y, testEndpoint as z };
1930
+ export { updateEndpoint as $, getStorageStats as A, pollCliLogin as B, downloadAttachments as C, getFunction as D, getEmail as E, listEndpoints as F, searchEmails as G, replayEmailWebhooks as H, listFilters as I, startCliLogin as J, sendEmail as K, listFunctionSecrets as L, listDeliveries as M, listDomains as N, getSendPermissions as O, listEmails as P, updateDomain as Q, listFunctions as R, discardEmailContent as S, getAccount as T, replyToEmail as U, replayDelivery as V, rotateWebhookSecret as W, testFunction as X, testEndpoint as Y, updateAccount as Z, deleteEmail as _, PrimitiveClient as a, deleteFunction as b, createPrimitiveClient as c, cliLogout as d, updateFilter as et, createEndpoint as f, deleteDomain as g, createFunctionSecret as h, PrimitiveApiError as i, getWebhookSecret as j, getSentEmail as k, operations as l, createFunction as m, DEFAULT_API_BASE_URL_2 as n, verifyDomain as nt, client as o, createFilter as p, setFunctionSecret as q, PrimitiveApiClient as r, createPrimitiveApiClient as s, DEFAULT_API_BASE_URL_1 as t, updateFunction as tt, addDomain as u, deleteEndpoint as v, downloadRawEmail as w, deleteFunctionSecret as x, deleteFilter as y, listSentEmails as z };