@sparkvault/sdk-js 15.4.0 → 15.6.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 +25 -0
- package/dist/errors.d.ts +2 -1
- package/dist/index.cjs +98 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +117 -4
- package/dist/index.mjs +98 -18
- package/dist/index.mjs.map +1 -1
- package/dist/notify/types.d.ts +5 -0
- package/dist/products/index.d.ts +2 -1
- package/dist/products/notify/index.d.ts +13 -1
- package/dist/products/notify/project-types.d.ts +77 -0
- package/dist/products/notify/projects.d.ts +21 -0
- package/dist/products/notify/types.d.ts +2 -0
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -134,6 +134,31 @@ app.post('/api/auth/login', async (req, res) => {
|
|
|
134
134
|
|
|
135
135
|
`products.identity`, `products.helpDesk`, `vaults.upload` and `health` send neither a Core JWT nor an `apiKey`. Help Desk uses only a desk customer session (`hdt_`), with cookies omitted. The upload widget needs the vault's Embedded Upload Widget setting enabled, with or without a `token`: it opens by reading the vault's upload info, a request that carries no VAT and is refused while the setting is off. The other modules call the Core API with a Core JWT (`accessToken` or `getAccessToken`) or, server-side, an `apiKey`; `notify` needs a SparkVault user's session JWT. Configuration, errors and TypeScript: the [reference](https://sparkvault.com/api/docs/sdk-js/#configuration-options).
|
|
136
136
|
|
|
137
|
+
## Notify projects
|
|
138
|
+
|
|
139
|
+
Use a named project for each separately operated product, brand or notification
|
|
140
|
+
service. Categories remain topics inside that project. Existing calls on
|
|
141
|
+
`sv.products.notify` continue to address Default.
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// Use an API key restricted to this project for a product integration.
|
|
145
|
+
const payroll = sv.products.notify.project('ntp_…');
|
|
146
|
+
await payroll.sendSecureMessage({
|
|
147
|
+
recipients: [{ id: 'employee_42', email: 'pat@example.com' }],
|
|
148
|
+
title: 'Your payslip is ready',
|
|
149
|
+
content: { payload: payslipPdfBase64, contentType: 'application/pdf' }
|
|
150
|
+
});
|
|
151
|
+
const history = await payroll.listSends({ limit: 20 });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`notify.projects.list/create/get/update/archive` manage project details under a
|
|
155
|
+
company credential; a newly created project is a free draft. Configure and
|
|
156
|
+
activate its plan in the console before sending. Programmatic plan changes use
|
|
157
|
+
`previewSubscription`, `subscribe` and `cancelSubscription` with an interactive
|
|
158
|
+
company-administrator session; an API key cannot authorize spending. Quote
|
|
159
|
+
amounts are exact decimal strings and should be repeated without floating-point
|
|
160
|
+
conversion. A first subscription can return a `checkout_url` for hosted payment.
|
|
161
|
+
|
|
137
162
|
## Help Desk
|
|
138
163
|
|
|
139
164
|
Create one KB-first support widget after the page body is ready:
|
package/dist/errors.d.ts
CHANGED
|
@@ -76,7 +76,8 @@ export declare class QuotaExceededError extends SparkVaultError {
|
|
|
76
76
|
constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null, serviceCode?: string);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
* Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED
|
|
79
|
+
* Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED or
|
|
80
|
+
* NOTIFY_PROJECT_SUBSCRIPTION_REQUIRED) — the account or selected project
|
|
80
81
|
* does not hold Notify and attempted a send that names no accepted send's
|
|
81
82
|
* `sendId` (a replay of an accepted send, the same request under its `sendId`,
|
|
82
83
|
* is answered with the stored send), or a config save that selects a new
|
package/dist/index.cjs
CHANGED
|
@@ -865,7 +865,8 @@ class QuotaExceededError extends SparkVaultError {
|
|
|
865
865
|
}
|
|
866
866
|
}
|
|
867
867
|
/**
|
|
868
|
-
* Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED
|
|
868
|
+
* Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED or
|
|
869
|
+
* NOTIFY_PROJECT_SUBSCRIPTION_REQUIRED) — the account or selected project
|
|
869
870
|
* does not hold Notify and attempted a send that names no accepted send's
|
|
870
871
|
* `sendId` (a replay of an accepted send, the same request under its `sendId`,
|
|
871
872
|
* is answered with the stored send), or a config save that selects a new
|
|
@@ -1027,6 +1028,7 @@ const RESOURCE_ID_PREFIXES = Object.freeze({
|
|
|
1027
1028
|
ingot: 'ing',
|
|
1028
1029
|
invite: 'inv',
|
|
1029
1030
|
notification: 'ntf',
|
|
1031
|
+
notifyProject: 'ntp',
|
|
1030
1032
|
requester: 'hrq',
|
|
1031
1033
|
routingRule: 'hdr',
|
|
1032
1034
|
savedReply: 'hds',
|
|
@@ -1669,7 +1671,7 @@ class HttpClient {
|
|
|
1669
1671
|
// A Notify send, or a config save selecting a new sending domain, refused
|
|
1670
1672
|
// because the account does not hold Notify is a billing gate, not a
|
|
1671
1673
|
// credential problem — give it its own catchable type.
|
|
1672
|
-
if (code === 'NOTIFY_SUBSCRIPTION_REQUIRED') {
|
|
1674
|
+
if (code === 'NOTIFY_SUBSCRIPTION_REQUIRED' || code === 'NOTIFY_PROJECT_SUBSCRIPTION_REQUIRED') {
|
|
1673
1675
|
return new NotifySubscriptionRequiredError(message, details, retryAfterMs, code);
|
|
1674
1676
|
}
|
|
1675
1677
|
return new AuthorizationError(message, details, retryAfterMs, code);
|
|
@@ -11599,6 +11601,67 @@ function mergePresetSend(preset, args) {
|
|
|
11599
11601
|
return merged;
|
|
11600
11602
|
}
|
|
11601
11603
|
|
|
11604
|
+
/** Reject malformed project paths before a credentialed request leaves. */
|
|
11605
|
+
function requireNotifyProjectId(projectId) {
|
|
11606
|
+
if (projectId === 'default' || isResourceIdOf('notifyProject', projectId))
|
|
11607
|
+
return projectId;
|
|
11608
|
+
throw new ValidationError('projectId must be a Notify project id or "default"', {
|
|
11609
|
+
field: 'projectId', received: projectId,
|
|
11610
|
+
});
|
|
11611
|
+
}
|
|
11612
|
+
/** Company-level project management. Creation saves a draft and charges nothing. */
|
|
11613
|
+
class NotifyProjectsModule {
|
|
11614
|
+
constructor(http) {
|
|
11615
|
+
this.http = http;
|
|
11616
|
+
}
|
|
11617
|
+
async list() {
|
|
11618
|
+
const response = await this.http.get(apiPath `/v1/products/notify/projects`);
|
|
11619
|
+
return response.data;
|
|
11620
|
+
}
|
|
11621
|
+
async create(options) {
|
|
11622
|
+
const response = await this.http.post(apiPath `/v1/products/notify/projects`, options);
|
|
11623
|
+
return response.data;
|
|
11624
|
+
}
|
|
11625
|
+
async get(projectId) {
|
|
11626
|
+
const id = requireNotifyProjectId(projectId);
|
|
11627
|
+
const response = await this.http.get(apiPath `/v1/products/notify/projects/${id}`);
|
|
11628
|
+
return response.data;
|
|
11629
|
+
}
|
|
11630
|
+
async update(projectId, options) {
|
|
11631
|
+
const id = requireNotifyProjectId(projectId);
|
|
11632
|
+
const response = await this.http.put(apiPath `/v1/products/notify/projects/${id}`, options);
|
|
11633
|
+
return response.data;
|
|
11634
|
+
}
|
|
11635
|
+
/** Archive after its paid plan has ended; Default cannot be archived. */
|
|
11636
|
+
async archive(projectId) {
|
|
11637
|
+
const id = requireNotifyProjectId(projectId);
|
|
11638
|
+
const response = await this.http.post(apiPath `/v1/products/notify/projects/${id}/archive`, {});
|
|
11639
|
+
return response.data;
|
|
11640
|
+
}
|
|
11641
|
+
/** Quote a named project's plan. Requires an interactive company-admin session. */
|
|
11642
|
+
async previewSubscription(projectId, options) {
|
|
11643
|
+
const id = requireNotifyProjectId(projectId);
|
|
11644
|
+
const response = await this.http.post(apiPath `/v1/products/notify/projects/${id}/subscription/preview`, { notifications_per_month: options.notificationsPerMonth });
|
|
11645
|
+
return response.data;
|
|
11646
|
+
}
|
|
11647
|
+
/** Purchase the reviewed plan on the company's invoice; an API key cannot authorize spending. */
|
|
11648
|
+
async subscribe(projectId, options) {
|
|
11649
|
+
const id = requireNotifyProjectId(projectId);
|
|
11650
|
+
const response = await this.http.post(apiPath `/v1/products/notify/projects/${id}/subscription`, {
|
|
11651
|
+
notifications_per_month: options.notificationsPerMonth,
|
|
11652
|
+
quoted_amount_due_now_usd: options.quotedAmountDueNowUsd,
|
|
11653
|
+
proration_date: options.prorationDate,
|
|
11654
|
+
});
|
|
11655
|
+
return response.data;
|
|
11656
|
+
}
|
|
11657
|
+
/** End a named project's plan at its paid period deadline; retained history stays readable. */
|
|
11658
|
+
async cancelSubscription(projectId) {
|
|
11659
|
+
const id = requireNotifyProjectId(projectId);
|
|
11660
|
+
const response = await this.http.delete(apiPath `/v1/products/notify/projects/${id}/subscription`);
|
|
11661
|
+
return response.data;
|
|
11662
|
+
}
|
|
11663
|
+
}
|
|
11664
|
+
|
|
11602
11665
|
/**
|
|
11603
11666
|
* Notify Product Module — the TENANT (sender) surface.
|
|
11604
11667
|
*
|
|
@@ -11684,8 +11747,25 @@ function buildNotifyPresetSend(preset, options) {
|
|
|
11684
11747
|
return mergePresetSend(bundle, options);
|
|
11685
11748
|
}
|
|
11686
11749
|
class NotifyProductModule {
|
|
11687
|
-
constructor(http) {
|
|
11750
|
+
constructor(http, projectId) {
|
|
11688
11751
|
this.http = http;
|
|
11752
|
+
this.projectId = projectId === undefined ? undefined : requireNotifyProjectId(projectId);
|
|
11753
|
+
this.projects = new NotifyProjectsModule(http);
|
|
11754
|
+
}
|
|
11755
|
+
/**
|
|
11756
|
+
* Bind every send, read and setting to one project. The original module keeps
|
|
11757
|
+
* addressing Default for existing integrations; this never changes global state.
|
|
11758
|
+
*/
|
|
11759
|
+
project(projectId) {
|
|
11760
|
+
return new NotifyProductModule(this.http, requireNotifyProjectId(projectId));
|
|
11761
|
+
}
|
|
11762
|
+
/** Compose two already-validated paths; project selection never enters a body. */
|
|
11763
|
+
path(literals, ...values) {
|
|
11764
|
+
const path = apiPath(literals, ...values);
|
|
11765
|
+
if (this.projectId === undefined)
|
|
11766
|
+
return path;
|
|
11767
|
+
const project = apiPath `/v1/products/notify/projects/${this.projectId}`;
|
|
11768
|
+
return `${project}${path.slice('/v1/products/notify'.length)}`;
|
|
11689
11769
|
}
|
|
11690
11770
|
// ── Send ────────────────────────────────────────────────────────────────────
|
|
11691
11771
|
/**
|
|
@@ -11754,7 +11834,7 @@ class NotifyProductModule {
|
|
|
11754
11834
|
if (options.ingot && (!options.ingot.vault?.id || !options.ingot.vault.vatToken)) {
|
|
11755
11835
|
throw new ValidationError('An ingot send requires its vault unsealed with sv.vaults.unseal (ingot.vault): only a key holder may send a vault file', { field: 'ingot.vault' });
|
|
11756
11836
|
}
|
|
11757
|
-
const response = await this.http.post(
|
|
11837
|
+
const response = await this.http.post(this.path `/v1/products/notify/send`, toSendBody(options), { vat: options.ingot?.vault.vatToken });
|
|
11758
11838
|
return response.data;
|
|
11759
11839
|
}
|
|
11760
11840
|
/**
|
|
@@ -11844,7 +11924,7 @@ class NotifyProductModule {
|
|
|
11844
11924
|
*/
|
|
11845
11925
|
async getInbox(options) {
|
|
11846
11926
|
requireRecipientId(options?.recipientId);
|
|
11847
|
-
const response = await this.http.get(
|
|
11927
|
+
const response = await this.http.get(this.path `/v1/products/notify/inbox`, {
|
|
11848
11928
|
query: {
|
|
11849
11929
|
recipient_id: options.recipientId,
|
|
11850
11930
|
state: options.state,
|
|
@@ -11882,7 +11962,7 @@ class NotifyProductModule {
|
|
|
11882
11962
|
received: options.state,
|
|
11883
11963
|
});
|
|
11884
11964
|
}
|
|
11885
|
-
const response = await this.http.post(
|
|
11965
|
+
const response = await this.http.post(this.path `/v1/products/notify/inbox/${id}/state`, { recipient_id: options.recipientId, created_at: options.createdAt, state: options.state });
|
|
11886
11966
|
return response.data;
|
|
11887
11967
|
}
|
|
11888
11968
|
/**
|
|
@@ -11903,7 +11983,7 @@ class NotifyProductModule {
|
|
|
11903
11983
|
if (!BULK_MARK_STATES$1.includes(options.state)) {
|
|
11904
11984
|
throw new ValidationError(`state must be one of ${BULK_MARK_STATES$1.join(', ')} (archive per-row instead)`, { field: 'state', received: options.state });
|
|
11905
11985
|
}
|
|
11906
|
-
const response = await this.http.post(
|
|
11986
|
+
const response = await this.http.post(this.path `/v1/products/notify/inbox/state`, {
|
|
11907
11987
|
recipient_id: options.recipientId,
|
|
11908
11988
|
state: options.state,
|
|
11909
11989
|
cursor: options.cursor,
|
|
@@ -11934,7 +12014,7 @@ class NotifyProductModule {
|
|
|
11934
12014
|
* } while (cursor);
|
|
11935
12015
|
*/
|
|
11936
12016
|
async listSends(options = {}) {
|
|
11937
|
-
const response = await this.http.get(
|
|
12017
|
+
const response = await this.http.get(this.path `/v1/products/notify/sends`, {
|
|
11938
12018
|
query: { limit: options.limit, cursor: options.cursor },
|
|
11939
12019
|
});
|
|
11940
12020
|
return response.data;
|
|
@@ -11980,7 +12060,7 @@ class NotifyProductModule {
|
|
|
11980
12060
|
received: options.mode,
|
|
11981
12061
|
});
|
|
11982
12062
|
}
|
|
11983
|
-
const response = await this.http.post(
|
|
12063
|
+
const response = await this.http.post(this.path `/v1/products/notify/sends/${sendId}/recall`, { recipient_ids: options.recipientIds, mode: options.mode });
|
|
11984
12064
|
return response.data;
|
|
11985
12065
|
}
|
|
11986
12066
|
// ── Status & receipts ───────────────────────────────────────────────────────
|
|
@@ -11994,7 +12074,7 @@ class NotifyProductModule {
|
|
|
11994
12074
|
*/
|
|
11995
12075
|
async getSendStatus(sendId) {
|
|
11996
12076
|
requireSendId(sendId);
|
|
11997
|
-
const response = await this.http.get(
|
|
12077
|
+
const response = await this.http.get(this.path `/v1/products/notify/sends/${sendId}/status`);
|
|
11998
12078
|
return response.data;
|
|
11999
12079
|
}
|
|
12000
12080
|
/**
|
|
@@ -12008,7 +12088,7 @@ class NotifyProductModule {
|
|
|
12008
12088
|
* const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
|
|
12009
12089
|
*/
|
|
12010
12090
|
async listReceipts(options = {}) {
|
|
12011
|
-
const response = await this.http.get(
|
|
12091
|
+
const response = await this.http.get(this.path `/v1/products/notify/receipts`, {
|
|
12012
12092
|
query: {
|
|
12013
12093
|
limit: options.limit,
|
|
12014
12094
|
cursor: options.cursor,
|
|
@@ -12034,7 +12114,7 @@ class NotifyProductModule {
|
|
|
12034
12114
|
*/
|
|
12035
12115
|
async getSendReceipts(sendId, options = {}) {
|
|
12036
12116
|
requireSendId(sendId);
|
|
12037
|
-
const response = await this.http.get(
|
|
12117
|
+
const response = await this.http.get(this.path `/v1/products/notify/sends/${sendId}/receipts`, { query: { cursor: options.cursor } });
|
|
12038
12118
|
return response.data;
|
|
12039
12119
|
}
|
|
12040
12120
|
// ── Config ──────────────────────────────────────────────────────────────────
|
|
@@ -12047,7 +12127,7 @@ class NotifyProductModule {
|
|
|
12047
12127
|
* const { effective, overrides } = await sv.products.notify.getConfig();
|
|
12048
12128
|
*/
|
|
12049
12129
|
async getConfig() {
|
|
12050
|
-
const response = await this.http.get(
|
|
12130
|
+
const response = await this.http.get(this.path `/v1/products/notify/config`);
|
|
12051
12131
|
return response.data;
|
|
12052
12132
|
}
|
|
12053
12133
|
/**
|
|
@@ -12096,7 +12176,7 @@ class NotifyProductModule {
|
|
|
12096
12176
|
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
|
|
12097
12177
|
throw new ValidationError('config patch must be an object');
|
|
12098
12178
|
}
|
|
12099
|
-
const response = await this.http.put(
|
|
12179
|
+
const response = await this.http.put(this.path `/v1/products/notify/config`, patch);
|
|
12100
12180
|
return response.data;
|
|
12101
12181
|
}
|
|
12102
12182
|
/**
|
|
@@ -12126,7 +12206,7 @@ class NotifyProductModule {
|
|
|
12126
12206
|
if (!NOTIFY_DESTINATION_KINDS.includes(kind)) {
|
|
12127
12207
|
throw new ValidationError(`kind must be one of ${NOTIFY_DESTINATION_KINDS.join(', ')}`);
|
|
12128
12208
|
}
|
|
12129
|
-
const response = await this.http.post(
|
|
12209
|
+
const response = await this.http.post(this.path `/v1/products/notify/destinations/${kind}/test`);
|
|
12130
12210
|
return response.data;
|
|
12131
12211
|
}
|
|
12132
12212
|
/**
|
|
@@ -12155,7 +12235,7 @@ class NotifyProductModule {
|
|
|
12155
12235
|
* if (sender.state === 'handle_required') promptForHandle();
|
|
12156
12236
|
*/
|
|
12157
12237
|
async getEmailSender() {
|
|
12158
|
-
const response = await this.http.get(
|
|
12238
|
+
const response = await this.http.get(this.path `/v1/products/notify/email-sender`);
|
|
12159
12239
|
return response.data;
|
|
12160
12240
|
}
|
|
12161
12241
|
}
|
|
@@ -25041,7 +25121,7 @@ class SparkVault {
|
|
|
25041
25121
|
}
|
|
25042
25122
|
/** Get the SDK version */
|
|
25043
25123
|
static get version() {
|
|
25044
|
-
return '15.
|
|
25124
|
+
return '15.6.0';
|
|
25045
25125
|
}
|
|
25046
25126
|
}
|
|
25047
25127
|
if (typeof window !== 'undefined') {
|
|
@@ -25065,6 +25145,7 @@ exports.NOTIFY_PRESETS = NOTIFY_PRESETS;
|
|
|
25065
25145
|
exports.NetworkError = NetworkError;
|
|
25066
25146
|
exports.NotifyModule = NotifyModule;
|
|
25067
25147
|
exports.NotifyProductModule = NotifyProductModule;
|
|
25148
|
+
exports.NotifyProjectsModule = NotifyProjectsModule;
|
|
25068
25149
|
exports.NotifySubscriptionRequiredError = NotifySubscriptionRequiredError;
|
|
25069
25150
|
exports.PlanRequiredError = PlanRequiredError;
|
|
25070
25151
|
exports.PopupBlockedError = PopupBlockedError;
|