@sparkvault/sdk-js 18.0.8 → 19.0.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/README.md CHANGED
@@ -310,13 +310,9 @@ await payroll.sendSecureMessage({
310
310
  const history = await payroll.listSends({ limit: 20 });
311
311
  ```
312
312
 
313
- `notify.projects.list/create/get/update/archive` manage project details under a
314
- company credential; a newly created project is a free draft. Configure and
315
- activate its plan in the console before sending. Programmatic plan changes use
316
- `previewSubscription`, `subscribe` and `cancelSubscription` with an interactive
317
- company-administrator session; an API key cannot authorize spending. Quote
318
- amounts are exact decimal strings and should be repeated without floating-point
319
- conversion. A first subscription can return a `checkout_url` for hosted payment.
313
+ - `notify.projects.list/create/get/update/archive` manage project details under a company credential.
314
+ - Create with a stable `request_id` (16 to 128 letters, numbers, underscores or hyphens); retries return the same active project.
315
+ - Notify is included. Configure delivery in the console and fund the shared wallet with purchased credits or credits included with another subscription before sending.
320
316
 
321
317
  ## Help Desk
322
318
 
package/dist/errors.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare class SparkVaultError extends Error {
21
21
  * answer named none (a gateway's HTML). A typed refusal's `code` names its
22
22
  * class of failure: one per 400 (`validation_error`), two per 401
23
23
  * (`authentication_error`, `UNAUTHORIZED`), 402 (`PLAN_REQUIRED`,
24
- * `QUOTA_EXCEEDED`, `USAGE_CREDITS_EXHAUSTED`) and 403 (`authorization_error`, `NOTIFY_SUBSCRIPTION_REQUIRED`;
24
+ * `QUOTA_EXCEEDED`, `USAGE_CREDITS_EXHAUSTED`) and 403 (`authorization_error`;
25
25
  * http.ts createErrorFromResponse), so this is what tells apart two
26
26
  * refusals that share a code.
27
27
  * Undefined on an error the SDK raised itself, on the Identity product's
@@ -86,19 +86,6 @@ export declare class QuotaExceededError extends SparkVaultError {
86
86
  readonly resource?: QuotaResource;
87
87
  constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null, serviceCode?: string);
88
88
  }
89
- /**
90
- * Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED or
91
- * NOTIFY_PROJECT_SUBSCRIPTION_REQUIRED): the account or selected project
92
- * does not hold Notify and attempted a send that names no accepted send's
93
- * `sendId` (a replay of an accepted send, the same request under its `sendId`,
94
- * is answered with the stored send), or a config save that selects a new
95
- * `email.sending_domain`. Distinct from a generic authorization failure: the
96
- * credential is fine and re-authenticating changes nothing, so surface a
97
- * subscribe CTA rather than a sign-in prompt.
98
- */
99
- export declare class NotifySubscriptionRequiredError extends SparkVaultError {
100
- constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null, serviceCode?: string);
101
- }
102
89
  export declare class NetworkError extends SparkVaultError {
103
90
  constructor(message: string, details?: Record<string, unknown>);
104
91
  }
package/dist/index.cjs CHANGED
@@ -883,23 +883,6 @@ class QuotaExceededError extends SparkVaultError {
883
883
  Object.setPrototypeOf(this, QuotaExceededError.prototype);
884
884
  }
885
885
  }
886
- /**
887
- * Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED or
888
- * NOTIFY_PROJECT_SUBSCRIPTION_REQUIRED): the account or selected project
889
- * does not hold Notify and attempted a send that names no accepted send's
890
- * `sendId` (a replay of an accepted send, the same request under its `sendId`,
891
- * is answered with the stored send), or a config save that selects a new
892
- * `email.sending_domain`. Distinct from a generic authorization failure: the
893
- * credential is fine and re-authenticating changes nothing, so surface a
894
- * subscribe CTA rather than a sign-in prompt.
895
- */
896
- class NotifySubscriptionRequiredError extends SparkVaultError {
897
- constructor(message, details, retryAfterMs = null, serviceCode) {
898
- super(message, 'NOTIFY_SUBSCRIPTION_REQUIRED', 403, details, retryAfterMs, serviceCode);
899
- this.name = 'NotifySubscriptionRequiredError';
900
- Object.setPrototypeOf(this, NotifySubscriptionRequiredError.prototype);
901
- }
902
- }
903
886
  class NetworkError extends SparkVaultError {
904
887
  constructor(message, details) {
905
888
  super(message, 'network_error', undefined, details);
@@ -1705,12 +1688,6 @@ class HttpClient {
1705
1688
  // PLAN_REQUIRED is the canonical 402 gate; treat any other 402 as one too.
1706
1689
  return new PlanRequiredError(message, details, retryAfterMs, code);
1707
1690
  case 403:
1708
- // A Notify send, or a config save selecting a new sending domain, refused
1709
- // because the account does not hold Notify is a billing gate, not a
1710
- // credential problem; give it its own catchable type.
1711
- if (code === 'NOTIFY_SUBSCRIPTION_REQUIRED' || code === 'NOTIFY_PROJECT_SUBSCRIPTION_REQUIRED') {
1712
- return new NotifySubscriptionRequiredError(message, details, retryAfterMs, code);
1713
- }
1714
1691
  return new AuthorizationError(message, details, retryAfterMs, code);
1715
1692
  default:
1716
1693
  return new SparkVaultError(message, code, status, details, retryAfterMs, code);
@@ -13438,12 +13415,7 @@ function requireNotifyProjectId(projectId) {
13438
13415
  field: 'projectId', received: projectId,
13439
13416
  });
13440
13417
  }
13441
- function subscriptionPlan(options) {
13442
- return options.billingModel === 'usage_credits'
13443
- ? { billing_model: 'usage_credits' }
13444
- : { notifications_per_month: options.notificationsPerMonth };
13445
- }
13446
- /** Company-level project management. Creation saves a draft and charges nothing. */
13418
+ /** Company-level project management. Creation is idempotent and charges nothing. */
13447
13419
  class NotifyProjectsModule {
13448
13420
  constructor(http) {
13449
13421
  this.http = http;
@@ -13466,34 +13438,12 @@ class NotifyProjectsModule {
13466
13438
  const response = await this.http.put(apiPath `/v1/products/notify/projects/${id}`, options);
13467
13439
  return response.data;
13468
13440
  }
13469
- /** Archive after its paid plan has ended; Default cannot be archived. */
13441
+ /** Archive an active project; Default cannot be archived. */
13470
13442
  async archive(projectId) {
13471
13443
  const id = requireNotifyProjectId(projectId);
13472
13444
  const response = await this.http.post(apiPath `/v1/products/notify/projects/${id}/archive`, {});
13473
13445
  return response.data;
13474
13446
  }
13475
- /** Quote a named project's plan. Requires an interactive company-admin session. */
13476
- async previewSubscription(projectId, options) {
13477
- const id = requireNotifyProjectId(projectId);
13478
- const response = await this.http.post(apiPath `/v1/products/notify/projects/${id}/subscription/preview`, subscriptionPlan(options));
13479
- return response.data;
13480
- }
13481
- /** Purchase the reviewed plan on the company's invoice; an API key cannot authorize spending. */
13482
- async subscribe(projectId, options) {
13483
- const id = requireNotifyProjectId(projectId);
13484
- const response = await this.http.post(apiPath `/v1/products/notify/projects/${id}/subscription`, {
13485
- ...subscriptionPlan(options),
13486
- quoted_amount_due_now_usd: options.quotedAmountDueNowUsd,
13487
- proration_date: options.prorationDate,
13488
- });
13489
- return response.data;
13490
- }
13491
- /** End a named project's plan at its paid period deadline; retained history stays readable. */
13492
- async cancelSubscription(projectId) {
13493
- const id = requireNotifyProjectId(projectId);
13494
- const response = await this.http.delete(apiPath `/v1/products/notify/projects/${id}/subscription`);
13495
- return response.data;
13496
- }
13497
13447
  }
13498
13448
 
13499
13449
  /**
@@ -13657,11 +13607,20 @@ class NotifyProductModule {
13657
13607
  throw new ValidationError(`sendId must be 1-${NOTIFY_SEND_ID_MAX_LENGTH} characters of letters, digits, and _ . : -`, { field: 'sendId', received: options.sendId });
13658
13608
  }
13659
13609
  }
13660
- if (!Array.isArray(options?.recipients) || options.recipients.length === 0) {
13661
- throw new ValidationError('recipients is required and must be non-empty', {
13610
+ const destinationOnly = Array.isArray(options?.recipients) && options.recipients.length === 0;
13611
+ if (!Array.isArray(options?.recipients) || (destinationOnly && (options.delivery !== 'plaintext' || !Array.isArray(options.destinations) || options.destinations.length === 0
13612
+ || !Array.isArray(options.channels) || options.channels.length !== 0))) {
13613
+ throw new ValidationError('Name recipients, or use a plaintext destination-only send with explicit destinations and empty channels', {
13662
13614
  field: 'recipients',
13663
13615
  });
13664
13616
  }
13617
+ if (Array.isArray(options.destinations) && (new Set(options.destinations).size !== options.destinations.length
13618
+ || options.destinations.some((kind) => !NOTIFY_DESTINATION_KINDS.includes(kind)))) {
13619
+ throw new ValidationError('destinations must name distinct destination kinds', { field: 'destinations' });
13620
+ }
13621
+ if (options.escalation?.stop_on_seen !== undefined && typeof options.escalation.stop_on_seen !== 'boolean') {
13622
+ throw new ValidationError('escalation.stop_on_seen must be true or false', { field: 'escalation.stop_on_seen' });
13623
+ }
13665
13624
  if (Boolean(options.content) === Boolean(options.ingot)) {
13666
13625
  throw new ValidationError('Provide exactly one content source: content OR ingot');
13667
13626
  }
@@ -14020,31 +13979,35 @@ class NotifyProductModule {
14020
13979
  /**
14021
13980
  * Post one test message to your destination of `kind` (a webhook, a Slack
14022
13981
  * channel or a Teams workflow) and learn what became of it, without a send:
14023
- * nothing reaches a recipient, no send is stored and nothing is metered, and
14024
- * the test never appears in send history. The post shows the title "Test
13982
+ * nothing reaches a recipient, no send is stored, and
13983
+ * the test spends destination delivery credits and never appears in send history. The post shows the title "Test
14025
13984
  * post from SparkVault Notify" under your organization's name, through the
14026
13985
  * sender a send's post takes. A webhook receives a body signed like any
14027
13986
  * other, typed `notify.destination.test`, naming no send, with a
14028
13987
  * `delivery_id` of its own. The post is made once and never tried again,
14029
- * so a fault a send's post would retry reads `failed`.
13988
+ * so a fault a send's post would retry reads `failed`. Retain request_id across retries;
13989
+ * a replay returns the saved verdict without another post or charge.
14030
13990
  *
14031
- * An org admin's call, on an account that holds Notify: anyone else is
13991
+ * An org admin's call: anyone else is
14032
13992
  * refused 403 `FORBIDDEN` (`details: { sections: ['destinations'],
14033
- * required_role: 'admin' }`), an account without Notify 403
14034
- * `NOTIFY_SUBSCRIPTION_REQUIRED`. A kind with no destination saved is 404
13993
+ * required_role: 'admin' }`). Insufficient credits returns a failed verdict
13994
+ * with reason `usage_credits_exhausted`. A kind with no destination saved is 404
14035
13995
  * `NOT_FOUND`, an organization name a send would be refused under is 409
14036
13996
  * (`NOTIFY_SENDER_NAME_REQUIRED` or `NOTIFY_SENDER_NAME_RESERVED`), and each
14037
13997
  * kind takes 20 tests an hour (429 `RATE_LIMIT_EXCEEDED`).
14038
13998
  *
14039
13999
  * @example
14040
- * const { state, reason } = await sv.products.notify.testDestination('webhook');
14000
+ * const { state, reason } = await sv.products.notify.testDestination('webhook', { request_id: 'test_webhook_0001' });
14041
14001
  * if (state !== 'delivered') console.warn(`Test post ${state}: ${reason}`);
14042
14002
  */
14043
- async testDestination(kind) {
14003
+ async testDestination(kind, request) {
14044
14004
  if (!NOTIFY_DESTINATION_KINDS.includes(kind)) {
14045
14005
  throw new ValidationError(`kind must be one of ${NOTIFY_DESTINATION_KINDS.join(', ')}`);
14046
14006
  }
14047
- const response = await this.http.post(this.path `/v1/products/notify/destinations/${kind}/test`);
14007
+ if (!request || typeof request.request_id !== 'string' || !/^[A-Za-z0-9_-]{16,128}$/.test(request.request_id)) {
14008
+ throw new ValidationError('request_id must be 16 to 128 letters, numbers, underscores or hyphens');
14009
+ }
14010
+ const response = await this.http.post(this.path `/v1/products/notify/destinations/${kind}/test`, request);
14048
14011
  return response.data;
14049
14012
  }
14050
14013
  /**
@@ -33066,7 +33029,7 @@ class SparkVault {
33066
33029
  }
33067
33030
  /** Get the SDK version */
33068
33031
  static get version() {
33069
- return '18.0.8';
33032
+ return '19.0.0';
33070
33033
  }
33071
33034
  }
33072
33035
  if (typeof window !== 'undefined') {
@@ -33092,7 +33055,6 @@ exports.NetworkError = NetworkError;
33092
33055
  exports.NotifyModule = NotifyModule;
33093
33056
  exports.NotifyProductModule = NotifyProductModule;
33094
33057
  exports.NotifyProjectsModule = NotifyProjectsModule;
33095
- exports.NotifySubscriptionRequiredError = NotifySubscriptionRequiredError;
33096
33058
  exports.PlanRequiredError = PlanRequiredError;
33097
33059
  exports.PopupBlockedError = PopupBlockedError;
33098
33060
  exports.PopupSeveredError = PopupSeveredError;