@sudoplatform/sudo-notification 1.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.
Files changed (153) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +20 -0
  3. package/cjs/gen/graphqlTypes.js +34 -0
  4. package/cjs/gen/graphqlTypes.js.map +1 -0
  5. package/cjs/index.js +10 -0
  6. package/cjs/index.js.map +1 -0
  7. package/cjs/private/apiClient.js +139 -0
  8. package/cjs/private/apiClient.js.map +1 -0
  9. package/cjs/private/codecs/sudoPlatformPayloadCodec.js +21 -0
  10. package/cjs/private/codecs/sudoPlatformPayloadCodec.js.map +1 -0
  11. package/cjs/private/constants.js +10 -0
  12. package/cjs/private/constants.js.map +1 -0
  13. package/cjs/private/transformers/buildTypeTransformer.js +30 -0
  14. package/cjs/private/transformers/buildTypeTransformer.js.map +1 -0
  15. package/cjs/private/transformers/errorTransformer.js +34 -0
  16. package/cjs/private/transformers/errorTransformer.js.map +1 -0
  17. package/cjs/private/transformers/notificationConfigurationTransformer.js +21 -0
  18. package/cjs/private/transformers/notificationConfigurationTransformer.js.map +1 -0
  19. package/cjs/private/transformers/notificationEnableStatusTransformer.js +32 -0
  20. package/cjs/private/transformers/notificationEnableStatusTransformer.js.map +1 -0
  21. package/cjs/private/transformers/notificationMetadataTransformer.js +17 -0
  22. package/cjs/private/transformers/notificationMetadataTransformer.js.map +1 -0
  23. package/cjs/private/types/canonicalPushSubscriptionJSON.js +8 -0
  24. package/cjs/private/types/canonicalPushSubscriptionJSON.js.map +1 -0
  25. package/cjs/private/types/notifiableServiceConfig.js +12 -0
  26. package/cjs/private/types/notifiableServiceConfig.js.map +1 -0
  27. package/cjs/private/types/notificationServiceConfig.js +17 -0
  28. package/cjs/private/types/notificationServiceConfig.js.map +1 -0
  29. package/cjs/private/types/sudoNotificationClientPrivateOptions.js +3 -0
  30. package/cjs/private/types/sudoNotificationClientPrivateOptions.js.map +1 -0
  31. package/cjs/public/errors.js +131 -0
  32. package/cjs/public/errors.js.map +1 -0
  33. package/cjs/public/index.js +13 -0
  34. package/cjs/public/index.js.map +1 -0
  35. package/cjs/public/sudoNotifiableClient.js +106 -0
  36. package/cjs/public/sudoNotifiableClient.js.map +1 -0
  37. package/cjs/public/sudoNotificationClient.js +164 -0
  38. package/cjs/public/sudoNotificationClient.js.map +1 -0
  39. package/cjs/public/types/buildType.js +18 -0
  40. package/cjs/public/types/buildType.js.map +1 -0
  41. package/cjs/public/types/index.js +20 -0
  42. package/cjs/public/types/index.js.map +1 -0
  43. package/cjs/public/types/notificationConfiguration.js +13 -0
  44. package/cjs/public/types/notificationConfiguration.js.map +1 -0
  45. package/cjs/public/types/notificationDeviceInfo.js +3 -0
  46. package/cjs/public/types/notificationDeviceInfo.js.map +1 -0
  47. package/cjs/public/types/notificationEnabledStatus.js +14 -0
  48. package/cjs/public/types/notificationEnabledStatus.js.map +1 -0
  49. package/cjs/public/types/notificationFilterItem.js +35 -0
  50. package/cjs/public/types/notificationFilterItem.js.map +1 -0
  51. package/cjs/public/types/notificationMetadata.js +22 -0
  52. package/cjs/public/types/notificationMetadata.js.map +1 -0
  53. package/cjs/public/types/notificationSchemaEntry.js +26 -0
  54. package/cjs/public/types/notificationSchemaEntry.js.map +1 -0
  55. package/cjs/public/types/sudoNotification.js +29 -0
  56. package/cjs/public/types/sudoNotification.js.map +1 -0
  57. package/cjs/public/types/sudoNotificationClientOptions.js +8 -0
  58. package/cjs/public/types/sudoNotificationClientOptions.js.map +1 -0
  59. package/cjs/public/types/sudoNotificationData.js +25 -0
  60. package/cjs/public/types/sudoNotificationData.js.map +1 -0
  61. package/cjs/public/types/sudoNotificationFilterClient.js +8 -0
  62. package/cjs/public/types/sudoNotificationFilterClient.js.map +1 -0
  63. package/lib/gen/graphqlTypes.js +31 -0
  64. package/lib/gen/graphqlTypes.js.map +1 -0
  65. package/lib/index.js +7 -0
  66. package/lib/index.js.map +1 -0
  67. package/lib/private/apiClient.js +135 -0
  68. package/lib/private/apiClient.js.map +1 -0
  69. package/lib/private/codecs/sudoPlatformPayloadCodec.js +17 -0
  70. package/lib/private/codecs/sudoPlatformPayloadCodec.js.map +1 -0
  71. package/lib/private/constants.js +7 -0
  72. package/lib/private/constants.js.map +1 -0
  73. package/lib/private/transformers/buildTypeTransformer.js +26 -0
  74. package/lib/private/transformers/buildTypeTransformer.js.map +1 -0
  75. package/lib/private/transformers/errorTransformer.js +30 -0
  76. package/lib/private/transformers/errorTransformer.js.map +1 -0
  77. package/lib/private/transformers/notificationConfigurationTransformer.js +17 -0
  78. package/lib/private/transformers/notificationConfigurationTransformer.js.map +1 -0
  79. package/lib/private/transformers/notificationEnableStatusTransformer.js +28 -0
  80. package/lib/private/transformers/notificationEnableStatusTransformer.js.map +1 -0
  81. package/lib/private/transformers/notificationMetadataTransformer.js +13 -0
  82. package/lib/private/transformers/notificationMetadataTransformer.js.map +1 -0
  83. package/lib/private/types/canonicalPushSubscriptionJSON.js +7 -0
  84. package/lib/private/types/canonicalPushSubscriptionJSON.js.map +1 -0
  85. package/lib/private/types/notifiableServiceConfig.js +8 -0
  86. package/lib/private/types/notifiableServiceConfig.js.map +1 -0
  87. package/lib/private/types/notificationServiceConfig.js +13 -0
  88. package/lib/private/types/notificationServiceConfig.js.map +1 -0
  89. package/lib/private/types/sudoNotificationClientPrivateOptions.js +2 -0
  90. package/lib/private/types/sudoNotificationClientPrivateOptions.js.map +1 -0
  91. package/lib/public/errors.js +116 -0
  92. package/lib/public/errors.js.map +1 -0
  93. package/lib/public/index.js +10 -0
  94. package/lib/public/index.js.map +1 -0
  95. package/lib/public/sudoNotifiableClient.js +102 -0
  96. package/lib/public/sudoNotifiableClient.js.map +1 -0
  97. package/lib/public/sudoNotificationClient.js +160 -0
  98. package/lib/public/sudoNotificationClient.js.map +1 -0
  99. package/lib/public/types/buildType.js +15 -0
  100. package/lib/public/types/buildType.js.map +1 -0
  101. package/lib/public/types/index.js +17 -0
  102. package/lib/public/types/index.js.map +1 -0
  103. package/lib/public/types/notificationConfiguration.js +9 -0
  104. package/lib/public/types/notificationConfiguration.js.map +1 -0
  105. package/lib/public/types/notificationDeviceInfo.js +2 -0
  106. package/lib/public/types/notificationDeviceInfo.js.map +1 -0
  107. package/lib/public/types/notificationEnabledStatus.js +11 -0
  108. package/lib/public/types/notificationEnabledStatus.js.map +1 -0
  109. package/lib/public/types/notificationFilterItem.js +31 -0
  110. package/lib/public/types/notificationFilterItem.js.map +1 -0
  111. package/lib/public/types/notificationMetadata.js +18 -0
  112. package/lib/public/types/notificationMetadata.js.map +1 -0
  113. package/lib/public/types/notificationSchemaEntry.js +22 -0
  114. package/lib/public/types/notificationSchemaEntry.js.map +1 -0
  115. package/lib/public/types/sudoNotification.js +25 -0
  116. package/lib/public/types/sudoNotification.js.map +1 -0
  117. package/lib/public/types/sudoNotificationClientOptions.js +7 -0
  118. package/lib/public/types/sudoNotificationClientOptions.js.map +1 -0
  119. package/lib/public/types/sudoNotificationData.js +21 -0
  120. package/lib/public/types/sudoNotificationData.js.map +1 -0
  121. package/lib/public/types/sudoNotificationFilterClient.js +7 -0
  122. package/lib/public/types/sudoNotificationFilterClient.js.map +1 -0
  123. package/package.json +107 -0
  124. package/types/gen/graphqlTypes.d.ts +229 -0
  125. package/types/index.d.ts +1 -0
  126. package/types/private/apiClient.d.ts +20 -0
  127. package/types/private/codecs/sudoPlatformPayloadCodec.d.ts +12 -0
  128. package/types/private/constants.d.ts +1 -0
  129. package/types/private/transformers/buildTypeTransformer.d.ts +6 -0
  130. package/types/private/transformers/errorTransformer.d.ts +4 -0
  131. package/types/private/transformers/notificationConfigurationTransformer.d.ts +6 -0
  132. package/types/private/transformers/notificationEnableStatusTransformer.d.ts +6 -0
  133. package/types/private/transformers/notificationMetadataTransformer.d.ts +5 -0
  134. package/types/private/types/canonicalPushSubscriptionJSON.d.ts +17 -0
  135. package/types/private/types/notifiableServiceConfig.d.ts +5 -0
  136. package/types/private/types/notificationServiceConfig.d.ts +7 -0
  137. package/types/private/types/sudoNotificationClientPrivateOptions.d.ts +13 -0
  138. package/types/public/errors.d.ts +81 -0
  139. package/types/public/index.d.ts +4 -0
  140. package/types/public/sudoNotifiableClient.d.ts +69 -0
  141. package/types/public/sudoNotificationClient.d.ts +109 -0
  142. package/types/public/types/buildType.d.ts +8 -0
  143. package/types/public/types/index.d.ts +11 -0
  144. package/types/public/types/notificationConfiguration.d.ts +6 -0
  145. package/types/public/types/notificationDeviceInfo.d.ts +41 -0
  146. package/types/public/types/notificationEnabledStatus.d.ts +4 -0
  147. package/types/public/types/notificationFilterItem.d.ts +13 -0
  148. package/types/public/types/notificationMetadata.d.ts +22 -0
  149. package/types/public/types/notificationSchemaEntry.d.ts +18 -0
  150. package/types/public/types/sudoNotification.d.ts +25 -0
  151. package/types/public/types/sudoNotificationClientOptions.d.ts +11 -0
  152. package/types/public/types/sudoNotificationData.d.ts +14 -0
  153. package/types/public/types/sudoNotificationFilterClient.d.ts +17 -0
@@ -0,0 +1,109 @@
1
+ import { SendTestNotificationInput } from '../gen/graphqlTypes';
2
+ import { CanonicalPushSubscriptionJSON } from '../private/types/canonicalPushSubscriptionJSON';
3
+ import { NotificationConfiguration } from './types/notificationConfiguration';
4
+ import { NotificationDeviceInfo } from './types/notificationDeviceInfo';
5
+ import { SudoNotificationClientOptions } from './types/sudoNotificationClientOptions';
6
+ /**
7
+ * Client used to interface with the Sudo Notification Platform service.
8
+ *
9
+ * It is recommended to code to this interface, rather than the implementation class (`DefaultSudoNotificationClient`) as
10
+ * the implementation class is only meant to be used for initializing an instance of the client.
11
+ */
12
+ export interface SudoNotificationClient {
13
+ /**
14
+ * Register to receive Sudo Platform web push notifications on a given
15
+ * Web Push API subscription.
16
+ *
17
+ * @param deviceInfo Information that identifies the user's device and application
18
+ * @param pushSubscription The web push subscription to register
19
+ *
20
+ * @throws NotSignedInError if user is not signed in
21
+ * @throws DeviceAlreadyRegisteredError if the same subscription has already been registered
22
+ * @throws DeviceCreateError if some other issue registering the subscription occurs
23
+ */
24
+ registerPushSubscription(deviceInfo: NotificationDeviceInfo, pushSubscription: PushSubscription): Promise<void>;
25
+ /**
26
+ * Update registration for the user with new push subscription information.
27
+ *
28
+ * @param deviceInfo Information that identifies the user's device and application
29
+ * @param pushSubscription
30
+ * Push subscription to update. The push subscription's endpoint must be
31
+ * the same. The only reason to update is to change the subscription's
32
+ * expiration.
33
+ *
34
+ * @throws {@link DeviceNotFoundError} if the push subscription has not been registered
35
+ * @throws {@link DeviceUpdateError} if the device update fails
36
+ */
37
+ updatePushSubscription(deviceInfo: NotificationDeviceInfo, pushSubscription: PushSubscription): Promise<void>;
38
+ /**
39
+ * Deregister a push subscription for the user
40
+ *
41
+ * @param deviceInfo Information that identifies the user's device and application
42
+ *
43
+ * @throws {@link DeviceNotFoundError} if the push subscription has not been registered
44
+ * @throws {@link DeviceDeleteError} if the deregistration fails
45
+ */
46
+ deregisterPushSubscription(deviceInfo: NotificationDeviceInfo): Promise<void>;
47
+ /**
48
+ * Get the user's current set of notification configurations for a push
49
+ * subscription.
50
+ *
51
+ * @param deviceInfo Information that identifies the user's device and application
52
+ *
53
+ * @throws {@link DeviceNotFoundError} if the device has not been registered
54
+ * @throws {@link DeviceReadError} if the retrieval fails for some other reason
55
+ */
56
+ getNotificationConfiguration(deviceInfo: NotificationDeviceInfo): Promise<NotificationConfiguration>;
57
+ /**
58
+ * Set the notification configuration for the user.
59
+ *
60
+ * @param deviceInfo Information that identifies the user's device and application
61
+ *
62
+ * @throws {@link DeviceNotFoundError} if the device has not been registered
63
+ * @throws {@link SchemaValidationError} if the retrieval fails for some other reason
64
+ */
65
+ setNotificationConfiguration(deviceInfo: NotificationDeviceInfo, config: NotificationConfiguration): Promise<void>;
66
+ /** @ignore */
67
+ sendTestNotification(input: SendTestNotificationInput): Promise<boolean>;
68
+ }
69
+ /**
70
+ * Default {@link SudoNotificationClient} for use by Sudo Platform applications.
71
+ */
72
+ export declare class DefaultSudoNotificationClient implements SudoNotificationClient {
73
+ private readonly apiClient;
74
+ private readonly sudoUserClient;
75
+ private readonly notifiableServices;
76
+ private readonly notificationServiceConfig;
77
+ private readonly logger;
78
+ /**
79
+ * Constructor
80
+ *
81
+ * @param opts Constructor options
82
+ * {@link SudoNotificationClientOptions.sudoUserClient} user client to authenticate the user
83
+ * {@link SudoNotificationClientOptions.notifiableServices} array of {@link SudoNotificationFilterClient}s from
84
+ * other notification enabled Sudo Platform SDKs.
85
+ *
86
+ * @throws
87
+ * NotificationServiceConfigNotFoundError if the Sudo Platform Notification Service is
88
+ * deployed in the Sudo Platform environment in which the SDK is being used.
89
+ *
90
+ * @throws
91
+ * InvalidConfigurationError if any of the services identified in opts.notifiableServices does
92
+ * not have notifications enabled.
93
+ */
94
+ constructor(opts: SudoNotificationClientOptions);
95
+ registerPushSubscription(deviceInfo: NotificationDeviceInfo, pushSubscription: PushSubscription): Promise<void>;
96
+ updatePushSubscription(deviceInfo: NotificationDeviceInfo, pushSubscription: PushSubscription): Promise<void>;
97
+ deregisterPushSubscription(deviceInfo: NotificationDeviceInfo): Promise<void>;
98
+ getNotificationConfiguration(deviceInfo: NotificationDeviceInfo): Promise<NotificationConfiguration>;
99
+ setNotificationConfiguration(deviceInfo: NotificationDeviceInfo, config: NotificationConfiguration): Promise<void>;
100
+ /** @ignore */
101
+ sendTestNotification(input: SendTestNotificationInput): Promise<boolean>;
102
+ /**
103
+ * Visible for testing
104
+ *
105
+ * @ignore
106
+ */
107
+ canonicalPushSubscriptionJson(json: PushSubscriptionJSON): CanonicalPushSubscriptionJSON;
108
+ private checkIsSignedInOrThrow;
109
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Build type fo the host application. Allows use of separate VAPID
3
+ * keys between debug and release deployments of the same application.
4
+ */
5
+ export declare enum BuildType {
6
+ RELEASE = "RELEASE",
7
+ DEBUG = "DEBUG"
8
+ }
@@ -0,0 +1,11 @@
1
+ export * from './buildType';
2
+ export * from './notificationConfiguration';
3
+ export * from './notificationDeviceInfo';
4
+ export * from './notificationEnabledStatus';
5
+ export * from './notificationFilterItem';
6
+ export * from './notificationMetadata';
7
+ export * from './notificationSchemaEntry';
8
+ export * from './sudoNotification';
9
+ export * from './sudoNotificationClientOptions';
10
+ export * from './sudoNotificationData';
11
+ export * from './sudoNotificationFilterClient';
@@ -0,0 +1,6 @@
1
+ import { NotificationFilterItem } from './notificationFilterItem';
2
+ export declare class NotificationConfiguration {
3
+ private _configs;
4
+ constructor(configs: NotificationFilterItem[]);
5
+ get configs(): ReadonlyArray<NotificationFilterItem>;
6
+ }
@@ -0,0 +1,41 @@
1
+ import { BuildType } from './buildType';
2
+ /**
3
+ * Information that uniquely identifies the device and application that is
4
+ * registering to receive web push notifications. Device IDs a scoped
5
+ * by the user's subject ID and applications' bundle ID and so only needs
6
+ * to be unique among all the user's devices. If bundle ID is shared across
7
+ * platforms then the device ID should be further qualified by platform by
8
+ * the consuming application.
9
+ *
10
+ * Notifications are sent to a subscription associated with a particular
11
+ * device ID, and the device ID is used to contain the notification filter
12
+ * configuration i.e. the rules for which notifications the user wants
13
+ * to receive on the particular device. Consuming applications may need to
14
+ * derive the device ID in a consistent way from the browser environment
15
+ * or persist a generated random device ID.
16
+ */
17
+ export interface NotificationDeviceInfo {
18
+ /**
19
+ * ID representing user and device that perists beyond
20
+ * lifetime of a single push subscription
21
+ */
22
+ deviceId: string;
23
+ /**
24
+ * Reverse DNS name idenfifying the application. For example
25
+ * com.sudoplatform.examples.notification.
26
+ */
27
+ bundleId: string;
28
+ /**
29
+ * Type of build. Allows for separate keys to be used in debug vs production
30
+ * environments.
31
+ */
32
+ buildType: BuildType;
33
+ /**
34
+ * Version of the application.
35
+ */
36
+ appVersion: string;
37
+ /**
38
+ * User's locale.
39
+ */
40
+ locale: string;
41
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum NotificationEnableStatus {
2
+ Enable = "ENABLE",
3
+ Disable = "DISABLE"
4
+ }
@@ -0,0 +1,13 @@
1
+ import { NotificationEnableStatus } from './notificationEnabledStatus';
2
+ export declare class NotificationFilterItem {
3
+ static readonly DEFAULT_RULE_STRING = "{\"==\": [1, 1]}";
4
+ private readonly _name;
5
+ private readonly _status;
6
+ private readonly _rules;
7
+ private readonly _meta;
8
+ constructor(name: string, status: boolean | undefined, rules: string | undefined, meta: string | undefined);
9
+ get name(): string;
10
+ get status(): NotificationEnableStatus;
11
+ get rules(): string;
12
+ get meta(): string;
13
+ }
@@ -0,0 +1,22 @@
1
+ import { NotificationSchemaEntry } from './notificationSchemaEntry';
2
+ /**
3
+ * Definition of all filterable notification properties of a specific
4
+ * service.
5
+ */
6
+ export declare class NotificationMetadata {
7
+ /**
8
+ * Name of service for the implementing Sudo Platform SDK. Matches the corresponding service's configuration
9
+ * section within sudoplatformconfig.json
10
+ */
11
+ readonly serviceName: string;
12
+ /** Array of schema entries, one for each filterable property */
13
+ readonly schema: ReadonlyArray<NotificationSchemaEntry>;
14
+ constructor(
15
+ /**
16
+ * Name of service for the implementing Sudo Platform SDK. Matches the corresponding service's configuration
17
+ * section within sudoplatformconfig.json
18
+ */
19
+ serviceName: string,
20
+ /** Array of schema entries, one for each filterable property */
21
+ schema: ReadonlyArray<NotificationSchemaEntry>);
22
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Schema of a single filterable property of a notification
3
+ */
4
+ export declare class NotificationSchemaEntry {
5
+ /** Description of the filterable property */
6
+ readonly description: string;
7
+ /** Name of the filterable property */
8
+ readonly fieldName: string;
9
+ /** Type of the filterable property */
10
+ readonly type: string;
11
+ constructor(
12
+ /** Description of the filterable property */
13
+ description: string,
14
+ /** Name of the filterable property */
15
+ fieldName: string,
16
+ /** Type of the filterable property */
17
+ type: string);
18
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Base SudoNotification class. Service specific SDKs provide concrete classes extending this
3
+ * base class that will be returned by SudoNotifiableClient.decodeData.
4
+ */
5
+ export declare abstract class SudoNotification {
6
+ /**
7
+ * Name of service for the implementing Sudo Platform SDK. Matches the corresponding
8
+ * service's configuration section within sudoplatformconfig.json
9
+ */
10
+ readonly serviceName: string;
11
+ /**
12
+ * Service specific type of notification.
13
+ */
14
+ readonly type: string;
15
+ constructor(
16
+ /**
17
+ * Name of service for the implementing Sudo Platform SDK. Matches the corresponding
18
+ * service's configuration section within sudoplatformconfig.json
19
+ */
20
+ serviceName: string,
21
+ /**
22
+ * Service specific type of notification.
23
+ */
24
+ type: string);
25
+ }
@@ -0,0 +1,11 @@
1
+ import { SudoUserClient } from '@sudoplatform/sudo-user';
2
+ import { SudoNotificationFilterClient } from './sudoNotificationFilterClient';
3
+ /**
4
+ * Options passed in to DefaultSudoNotificationClient's constructor
5
+ */
6
+ export interface SudoNotificationClientOptions {
7
+ /** Sudo User client to use. No default */
8
+ sudoUserClient: SudoUserClient;
9
+ /** Array of notifiable Sudo Platform services */
10
+ notifiableServices: SudoNotificationFilterClient[];
11
+ }
@@ -0,0 +1,14 @@
1
+ export declare class SudoNotificationData {
2
+ readonly serviceName: string;
3
+ readonly data?: string | undefined;
4
+ /**
5
+ *
6
+ * @param serviceName
7
+ * Name of service for the implementing Sudo Platform SDK. Matches the corresponding
8
+ * service's configuration section within sudoplatformconfig.json
9
+ *
10
+ * @param data
11
+ * Opaque, serialized service specific notification data
12
+ */
13
+ constructor(serviceName: string, data?: string | undefined);
14
+ }
@@ -0,0 +1,17 @@
1
+ import { NotificationMetadata } from './notificationMetadata';
2
+ /**
3
+ * Client used to provide filter schema information to the notification SDk. Each Sudo Platform service SDK that has
4
+ * notifications provides an implementation of this protocol that must be passed to `DefaultSudoNotificationClient`
5
+ * on construction.
6
+ */
7
+ export interface SudoNotificationFilterClient {
8
+ /**
9
+ * Name of service for the implementing Sudo Platform SDK. Matches the corresponding service's configuration
10
+ * section within sudoplatformconfig.json
11
+ */
12
+ serviceName: string;
13
+ /**
14
+ * Return the schema describing properties available for filtering for the specific service
15
+ */
16
+ getSchema(): NotificationMetadata;
17
+ }