@proveanything/smartlinks 1.1.25 → 1.2.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.
@@ -1,49 +1,86 @@
1
- import type { SendNotificationRequest, SendNotificationResponse, CommunicationEvent, CommsQueryByUser, CommsRecipientIdsQuery, CommsRecipientsWithoutActionQuery, CommsRecipientsWithActionQuery, RecipientId, RecipientWithOutcome, LogCommunicationEventBody, LogBulkCommunicationEventsBody, AppendResult, AppendBulkResult } from "../types/comms";
1
+ import type { CommunicationEvent, CommsQueryByUser, CommsRecipientIdsQuery, CommsRecipientsWithoutActionQuery, CommsRecipientsWithActionQuery, RecipientId, RecipientWithOutcome, LogCommunicationEventBody, LogBulkCommunicationEventsBody, AppendResult, AppendBulkResult } from "../types/comms";
2
2
  /**
3
3
  * Communications namespace for sending notifications and managing user communications
4
4
  */
5
5
  export declare namespace comms {
6
6
  /**
7
- * Send a notification to specified targets within a collection.
8
- *
9
- * Supports multiple delivery methods including push notifications, email, and wallet pass updates.
10
- * The notification will be delivered based on user preferences and the specified delivery mode.
11
- *
12
- * @param collectionId - ID of the collection containing the notification targets
13
- * @param request - Notification configuration including targets, severity, and content templates
14
- * @returns Promise resolving to the notification enqueue/queue status and totals
15
- * @throws ErrorResponse if the request fails or targets are invalid
16
- *
17
- * @example
18
- * ```typescript
19
- * const result = await comms.sendNotification('my-collection', {
20
- * subjectTargets: [{ type: 'product', id: 'prod_123' }],
21
- * severity: 'important',
22
- * mode: 'preferred',
23
- * template: {
24
- * push: {
25
- * title: 'Update available',
26
- * body: 'We\'ve shipped an important update.',
27
- * icon: 'https://cdn.example.com/brand/logo-128.png'
28
- * },
29
- * email: {
30
- * subject: 'Important update for your product',
31
- * body: 'There\'s an important update. Open your pass or profile to learn more.'
32
- * },
33
- * walletUpdate: {
34
- * textModulesData: [
35
- * { id: 'notice', header: 'Update', body: 'Open your wallet pass for details.' }
36
- * ]
37
- * }
38
- * }
39
- * })
40
- * if (result.ok) {
41
- * console.log('Notification queued:', result.notificationId)
42
- * console.log('Totals:', result.status.totals)
43
- * }
44
- * ```
45
- */
46
- function sendNotification(collectionId: string, request: SendNotificationRequest): Promise<SendNotificationResponse>;
7
+ * Public: Get VAPID public key used for Web Push subscriptions.
8
+ * GET /public/collection/:collectionId/comm/push/vapidPublicKey
9
+ * Note: Key may be global; path is collection-scoped for consistency.
10
+ */
11
+ function getPushVapidPublicKey(collectionId: string): Promise<import("../types/comms").PushVapidResponse>;
12
+ /**
13
+ * Public: Register a Web Push subscription under unified comms.
14
+ * POST /public/collection/:collectionId/comm/push/register
15
+ */
16
+ function registerPush(collectionId: string, body: import("../types/comms").PushSubscribeRequest): Promise<import("../types/comms").PushSubscribeResponse>;
17
+ /**
18
+ * Admin: Get current comms settings for a collection.
19
+ * GET /admin/collection/:collectionId/comm.settings
20
+ * Optional query: includeSecret=true to include unsub.secret in response.
21
+ */
22
+ function getSettings(collectionId: string, opts?: {
23
+ includeSecret?: boolean;
24
+ }): Promise<import("../types/comms").CommsSettingsGetResponse>;
25
+ /**
26
+ * Admin: Patch comms settings for a collection.
27
+ * PATCH /admin/collection/:collectionId/comm.settings
28
+ */
29
+ function patchSettings(collectionId: string, body: import("../types/comms").CommsSettingsPatchBody): Promise<import("../types/comms").CommsSettingsGetResponse>;
30
+ /**
31
+ * Public: Fetch configured topics for a collection.
32
+ * GET /public/collection/:collectionId/comm/topics
33
+ */
34
+ function getPublicTopics(collectionId: string): Promise<import("../types/comms").CommsPublicTopicsResponse>;
35
+ /**
36
+ * Public: Unsubscribe a contact from a category or channel.
37
+ * GET /public/collection/:collectionId/comm/unsubscribe
38
+ */
39
+ function unsubscribe(collectionId: string, query: import("../types/comms").UnsubscribeQuery): Promise<import("../types/comms").UnsubscribeResponse>;
40
+ /**
41
+ * Public: Upsert default consent for a contact.
42
+ * POST /public/collection/:collectionId/comm/consent
43
+ */
44
+ function upsertConsent(collectionId: string, body: import("../types/comms").CommsConsentUpsertRequest): Promise<{
45
+ ok: true;
46
+ }>;
47
+ /**
48
+ * Public: Upsert preferences for a specific subject (or default if subject omitted).
49
+ * POST /public/collection/:collectionId/comm/preferences
50
+ */
51
+ function upsertPreferences(collectionId: string, body: import("../types/comms").CommsPreferencesUpsertRequest): Promise<{
52
+ ok: true;
53
+ }>;
54
+ /**
55
+ * Public: Subscribe/unsubscribe contact to a subject.
56
+ * POST /public/collection/:collectionId/comm/subscribe
57
+ */
58
+ function subscribe(collectionId: string, body: import("../types/comms").CommsSubscribeRequest): Promise<import("../types/comms").CommsSubscribeResponse>;
59
+ /**
60
+ * Public: Check subscription status for a subject.
61
+ * GET /public/collection/:collectionId/comm/subscription/check
62
+ */
63
+ function checkSubscription(collectionId: string, query: import("../types/comms").CommsSubscriptionCheckQuery): Promise<import("../types/comms").CommsSubscriptionCheckResponse>;
64
+ /**
65
+ * Public: List registered contact methods.
66
+ * GET /public/collection/:collectionId/comm/methods
67
+ */
68
+ function listMethods(collectionId: string, query: import("../types/comms").CommsListMethodsQuery): Promise<import("../types/comms").CommsListMethodsResponse>;
69
+ /**
70
+ * Public: Register email method for a contact.
71
+ * POST /public/collection/:collectionId/comm/email/register
72
+ */
73
+ function registerEmail(collectionId: string, body: import("../types/comms").RegisterEmailMethodRequest): Promise<import("../types/comms").RegisterMethodResponse>;
74
+ /**
75
+ * Public: Register SMS method for a contact.
76
+ * POST /public/collection/:collectionId/comm/sms/register
77
+ */
78
+ function registerSms(collectionId: string, body: import("../types/comms").RegisterSmsMethodRequest): Promise<import("../types/comms").RegisterMethodResponse>;
79
+ /**
80
+ * Public: Resolve contacts for a subject with identity hints.
81
+ * POST /public/collection/:collectionId/comm/subscriptions/resolve
82
+ */
83
+ function resolveSubscriptions(collectionId: string, body: import("../types/comms").SubscriptionsResolveRequest): Promise<import("../types/comms").SubscriptionsResolveResponse>;
47
84
  /**
48
85
  * Analytics: Query communication events by user or contact.
49
86
  * POST /admin/collection/:collectionId/comm/query/by-user
package/dist/api/comms.js CHANGED
@@ -1,56 +1,165 @@
1
1
  // src/api/comms.ts
2
2
  // Communications and notifications API for Smartlinks
3
- import { post } from "../http";
3
+ import { post, request, patch } from "../http";
4
4
  /**
5
5
  * Communications namespace for sending notifications and managing user communications
6
6
  */
7
7
  export var comms;
8
8
  (function (comms) {
9
9
  /**
10
- * Send a notification to specified targets within a collection.
11
- *
12
- * Supports multiple delivery methods including push notifications, email, and wallet pass updates.
13
- * The notification will be delivered based on user preferences and the specified delivery mode.
14
- *
15
- * @param collectionId - ID of the collection containing the notification targets
16
- * @param request - Notification configuration including targets, severity, and content templates
17
- * @returns Promise resolving to the notification enqueue/queue status and totals
18
- * @throws ErrorResponse if the request fails or targets are invalid
19
- *
20
- * @example
21
- * ```typescript
22
- * const result = await comms.sendNotification('my-collection', {
23
- * subjectTargets: [{ type: 'product', id: 'prod_123' }],
24
- * severity: 'important',
25
- * mode: 'preferred',
26
- * template: {
27
- * push: {
28
- * title: 'Update available',
29
- * body: 'We\'ve shipped an important update.',
30
- * icon: 'https://cdn.example.com/brand/logo-128.png'
31
- * },
32
- * email: {
33
- * subject: 'Important update for your product',
34
- * body: 'There\'s an important update. Open your pass or profile to learn more.'
35
- * },
36
- * walletUpdate: {
37
- * textModulesData: [
38
- * { id: 'notice', header: 'Update', body: 'Open your wallet pass for details.' }
39
- * ]
40
- * }
41
- * }
42
- * })
43
- * if (result.ok) {
44
- * console.log('Notification queued:', result.notificationId)
45
- * console.log('Totals:', result.status.totals)
46
- * }
47
- * ```
48
- */
49
- async function sendNotification(collectionId, request) {
50
- const path = `/admin/collection/${encodeURIComponent(collectionId)}/comm/notify`;
51
- return post(path, request);
52
- }
53
- comms.sendNotification = sendNotification;
10
+ * Public: Get VAPID public key used for Web Push subscriptions.
11
+ * GET /public/collection/:collectionId/comm/push/vapidPublicKey
12
+ * Note: Key may be global; path is collection-scoped for consistency.
13
+ */
14
+ async function getPushVapidPublicKey(collectionId) {
15
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/push/vapidPublicKey`;
16
+ return request(path);
17
+ }
18
+ comms.getPushVapidPublicKey = getPushVapidPublicKey;
19
+ /**
20
+ * Public: Register a Web Push subscription under unified comms.
21
+ * POST /public/collection/:collectionId/comm/push/register
22
+ */
23
+ async function registerPush(collectionId, body) {
24
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/push/register`;
25
+ return post(path, body);
26
+ }
27
+ comms.registerPush = registerPush;
28
+ // Admin Comms Settings
29
+ /**
30
+ * Admin: Get current comms settings for a collection.
31
+ * GET /admin/collection/:collectionId/comm.settings
32
+ * Optional query: includeSecret=true to include unsub.secret in response.
33
+ */
34
+ async function getSettings(collectionId, opts = {}) {
35
+ const params = new URLSearchParams();
36
+ if (opts.includeSecret)
37
+ params.set('includeSecret', 'true');
38
+ const qs = params.toString() ? `?${params.toString()}` : '';
39
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/comm.settings${qs}`;
40
+ return request(path);
41
+ }
42
+ comms.getSettings = getSettings;
43
+ /**
44
+ * Admin: Patch comms settings for a collection.
45
+ * PATCH /admin/collection/:collectionId/comm.settings
46
+ */
47
+ async function patchSettings(collectionId, body) {
48
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/comm.settings`;
49
+ return patch(path, body);
50
+ }
51
+ comms.patchSettings = patchSettings;
52
+ /**
53
+ * Public: Fetch configured topics for a collection.
54
+ * GET /public/collection/:collectionId/comm/topics
55
+ */
56
+ async function getPublicTopics(collectionId) {
57
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/topics`;
58
+ return request(path);
59
+ }
60
+ comms.getPublicTopics = getPublicTopics;
61
+ /**
62
+ * Public: Unsubscribe a contact from a category or channel.
63
+ * GET /public/collection/:collectionId/comm/unsubscribe
64
+ */
65
+ async function unsubscribe(collectionId, query) {
66
+ const params = new URLSearchParams();
67
+ params.set('contactId', query.contactId);
68
+ if (query.topic)
69
+ params.set('topic', query.topic);
70
+ if (query.channel)
71
+ params.set('channel', query.channel);
72
+ if (query.token)
73
+ params.set('token', query.token);
74
+ const qs = `?${params.toString()}`;
75
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/unsubscribe${qs}`;
76
+ return request(path);
77
+ }
78
+ comms.unsubscribe = unsubscribe;
79
+ /**
80
+ * Public: Upsert default consent for a contact.
81
+ * POST /public/collection/:collectionId/comm/consent
82
+ */
83
+ async function upsertConsent(collectionId, body) {
84
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/consent`;
85
+ return post(path, body);
86
+ }
87
+ comms.upsertConsent = upsertConsent;
88
+ /**
89
+ * Public: Upsert preferences for a specific subject (or default if subject omitted).
90
+ * POST /public/collection/:collectionId/comm/preferences
91
+ */
92
+ async function upsertPreferences(collectionId, body) {
93
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/preferences`;
94
+ return post(path, body);
95
+ }
96
+ comms.upsertPreferences = upsertPreferences;
97
+ /**
98
+ * Public: Subscribe/unsubscribe contact to a subject.
99
+ * POST /public/collection/:collectionId/comm/subscribe
100
+ */
101
+ async function subscribe(collectionId, body) {
102
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/subscribe`;
103
+ return post(path, body);
104
+ }
105
+ comms.subscribe = subscribe;
106
+ /**
107
+ * Public: Check subscription status for a subject.
108
+ * GET /public/collection/:collectionId/comm/subscription/check
109
+ */
110
+ async function checkSubscription(collectionId, query) {
111
+ const params = new URLSearchParams();
112
+ params.set('contactId', query.contactId);
113
+ params.set('subjectType', query.subjectType);
114
+ params.set('subjectId', query.subjectId);
115
+ if (query.productId)
116
+ params.set('productId', String(query.productId));
117
+ const qs = `?${params.toString()}`;
118
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/subscription/check${qs}`;
119
+ return request(path);
120
+ }
121
+ comms.checkSubscription = checkSubscription;
122
+ /**
123
+ * Public: List registered contact methods.
124
+ * GET /public/collection/:collectionId/comm/methods
125
+ */
126
+ async function listMethods(collectionId, query) {
127
+ const params = new URLSearchParams();
128
+ params.set('contactId', query.contactId);
129
+ if (query.type)
130
+ params.set('type', query.type);
131
+ const qs = `?${params.toString()}`;
132
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/methods${qs}`;
133
+ return request(path);
134
+ }
135
+ comms.listMethods = listMethods;
136
+ /**
137
+ * Public: Register email method for a contact.
138
+ * POST /public/collection/:collectionId/comm/email/register
139
+ */
140
+ async function registerEmail(collectionId, body) {
141
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/email/register`;
142
+ return post(path, body);
143
+ }
144
+ comms.registerEmail = registerEmail;
145
+ /**
146
+ * Public: Register SMS method for a contact.
147
+ * POST /public/collection/:collectionId/comm/sms/register
148
+ */
149
+ async function registerSms(collectionId, body) {
150
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/sms/register`;
151
+ return post(path, body);
152
+ }
153
+ comms.registerSms = registerSms;
154
+ /**
155
+ * Public: Resolve contacts for a subject with identity hints.
156
+ * POST /public/collection/:collectionId/comm/subscriptions/resolve
157
+ */
158
+ async function resolveSubscriptions(collectionId, body) {
159
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/comm/subscriptions/resolve`;
160
+ return post(path, body);
161
+ }
162
+ comms.resolveSubscriptions = resolveSubscriptions;
54
163
  /**
55
164
  * Analytics: Query communication events by user or contact.
56
165
  * POST /admin/collection/:collectionId/comm/query/by-user
package/dist/index.d.ts CHANGED
@@ -4,10 +4,11 @@ export * from "./types";
4
4
  export { iframe } from "./iframe";
5
5
  export type { LoginResponse, VerifyTokenResponse, AccountInfoResponse, } from "./api/auth";
6
6
  export type { UserAccountRegistrationRequest, } from "./types/auth";
7
- export type { SendNotificationRequest, SendNotificationResponse, NotificationSubjectTarget, NotificationTemplate, PushNotificationTemplate, EmailNotificationTemplate, WalletUpdateTemplate, CommunicationEvent, CommsQueryByUser, CommsRecipientIdsQuery, CommsRecipientsWithoutActionQuery, CommsRecipientsWithActionQuery, RecipientId, RecipientWithOutcome, LogCommunicationEventBody, LogBulkCommunicationEventsBody, AppendResult, AppendBulkResult, } from "./types/comms";
7
+ export type { CommunicationEvent, CommsQueryByUser, CommsRecipientIdsQuery, CommsRecipientsWithoutActionQuery, CommsRecipientsWithActionQuery, RecipientId, RecipientWithOutcome, LogCommunicationEventBody, LogBulkCommunicationEventsBody, AppendResult, AppendBulkResult, CommsSettings, TopicConfig, CommsSettingsGetResponse, CommsSettingsPatchBody, CommsPublicTopicsResponse, UnsubscribeQuery, UnsubscribeResponse, CommsConsentUpsertRequest, CommsPreferencesUpsertRequest, CommsSubscribeRequest, CommsSubscribeResponse, CommsSubscriptionCheckQuery, CommsSubscriptionCheckResponse, CommsListMethodsQuery, CommsListMethodsResponse, RegisterEmailMethodRequest, RegisterSmsMethodRequest, RegisterMethodResponse, SubscriptionsResolveRequest, SubscriptionsResolveResponse, } from "./types/comms";
8
8
  export type { AttestationResponse, AttestationCreateRequest, AttestationUpdateRequest, } from "./types/attestation";
9
9
  export type { BatchResponse, BatchCreateRequest, BatchUpdateRequest, } from "./types/batch";
10
10
  export type { VariantResponse, VariantCreateRequest, VariantUpdateRequest, } from "./types/variant";
11
+ export type { BroadcastSendRequest } from "./types/broadcasts";
11
12
  export type { AppConfigOptions } from "./api/appConfiguration";
12
13
  export type { ProductCreateRequest, ProductUpdateRequest, Product, } from "./types/product";
13
14
  export type { Collection, CollectionResponse, CollectionCreateRequest, CollectionUpdateRequest, } from "./types/collection";
@@ -20,6 +20,18 @@ export interface BroadcastRecord {
20
20
  color?: string;
21
21
  };
22
22
  broadcastType?: string;
23
+ /** Required topic key for consent enforcement (e.g. newsletter, marketing, critical) */
24
+ topic: string;
25
+ /** Per-channel enablement/priority and optional template overrides */
26
+ channelSettings?: {
27
+ mode?: 'preferred' | 'channels' | 'all';
28
+ channels?: Array<{
29
+ channel: import('./broadcasts').BroadcastChannel;
30
+ enabled?: boolean;
31
+ priority?: number;
32
+ templateId?: string;
33
+ }>;
34
+ };
23
35
  [key: string]: unknown;
24
36
  };
25
37
  createdAt: string;
@@ -36,23 +48,55 @@ export interface BroadcastRecipientsResponse {
36
48
  offset: number;
37
49
  note?: string;
38
50
  }
51
+ export type BroadcastChannel = 'email' | 'push' | 'sms' | 'wallet';
39
52
  export interface BroadcastPreviewRequest {
40
53
  contactId?: string;
41
54
  email?: string;
55
+ phone?: string;
42
56
  props?: Record<string, any>;
57
+ channelOverride?: BroadcastChannel;
58
+ hydrate?: boolean;
59
+ include?: {
60
+ product?: boolean;
61
+ proof?: boolean;
62
+ user?: boolean;
63
+ [k: string]: boolean | undefined;
64
+ };
43
65
  }
44
- export interface BroadcastPreviewResponse {
45
- ok: boolean;
66
+ export type BroadcastPreviewResponse = {
67
+ channel: 'email';
46
68
  html: string;
47
- }
48
- export interface BroadcastSendTestRequest {
49
- to: string;
50
69
  subject?: string;
70
+ templateId?: string;
71
+ } | {
72
+ channel: 'push';
73
+ payload: any;
74
+ subject?: string;
75
+ } | {
76
+ channel: 'sms';
77
+ body: string;
78
+ } | {
79
+ channel: 'wallet';
80
+ payload: any;
81
+ };
82
+ export interface BroadcastSendTestRequest {
83
+ contactId?: string;
84
+ email?: string;
85
+ phone?: string;
51
86
  props?: Record<string, any>;
87
+ channelOverride?: BroadcastChannel;
88
+ hydrate?: boolean;
89
+ include?: {
90
+ product?: boolean;
91
+ proof?: boolean;
92
+ user?: boolean;
93
+ [k: string]: boolean | undefined;
94
+ };
52
95
  }
53
96
  export interface BroadcastSendTestResponse {
54
97
  ok: boolean;
55
98
  id?: string;
99
+ channel?: BroadcastChannel;
56
100
  }
57
101
  export interface BroadcastSendManualRequest {
58
102
  limit?: number;
@@ -80,10 +124,23 @@ export interface BroadcastSendManualResponse {
80
124
  message?: string;
81
125
  }>;
82
126
  }
127
+ export interface BroadcastSendRequest {
128
+ pageSize?: number;
129
+ maxPages?: number;
130
+ sharedContext?: Record<string, any>;
131
+ channel?: BroadcastChannel;
132
+ hydrate?: boolean;
133
+ include?: {
134
+ product?: boolean;
135
+ proof?: boolean;
136
+ user?: boolean;
137
+ [k: string]: boolean | undefined;
138
+ };
139
+ }
83
140
  export interface BroadcastAppendEventBody {
84
141
  broadcastId: string;
85
142
  contactId?: string;
86
- channel?: 'email';
143
+ channel?: BroadcastChannel;
87
144
  templateId?: string;
88
145
  eventType: string;
89
146
  outcome?: 'success' | 'failed';