diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml new file mode 100644 index 0000000..e1e59f5 --- /dev/null +++ b/.github/workflows/release-package.yml @@ -0,0 +1,23 @@ +name: Node.js Package + +on: + release: + types: [created] + +jobs: + publish-package: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '18.16' + registry-url: https://npm.pkg.github.com/ + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..5ad686c --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@hi3g-access:registry=https://npm.pkg.github.com diff --git a/README.md b/README.md index c12202c..d8453ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @allboatsrise/expo-marketingcloudsdk +# @hi3g-access/expo-marketingcloudsdk This is an Expo module that provides a wrapper around the Salesforce Marketing Cloud SDK for iOS and Android. @@ -9,14 +9,17 @@ It allows Expo-based apps to integrate with the Marketing Cloud SDK. To install the package use your preferred package manager: ```bash -npm install @allboatsrise/expo-marketingcloudsdk expo-notifications zod +npm install @hi3g-access/expo-marketingcloudsdk expo-notifications zod ``` + or + ```bash -yarn add @allboatsrise/expo-marketingcloudsdk expo-notifications zod +yarn add @hi3g-access/expo-marketingcloudsdk expo-notifications zod ``` ## Plugin setup + #### [View parameters](#plugin-parameters) Add package to `plugins` in `app.js`/`app.config.js` with minimal configuration. @@ -25,7 +28,7 @@ Add package to `plugins` in `app.js`/`app.config.js` with minimal configuration. "expo": { "plugins": [ [ - "@allboatsrise/expo-marketingcloudsdk", { + "@hi3g-access/expo-marketingcloudsdk", { "appId": "<< MARKETING_CLOUD_APP_ID >>", "accessToken": "<< MARKETING_CLOUD_ACCESS_TOKEN >>", "serverUrl": "<< MARKETING_CLOUD_SERVER_URL >>", @@ -40,7 +43,7 @@ Sample initialization of notifications in the app ```typescript import * as Notifications from 'expo-notifications' -import * as MarketingCloud from '@allboatsrise/expo-marketingcloudsdk' +import * as MarketingCloud from '@hi3g-access/expo-marketingcloudsdk' // ensure push notifications appear regardless whether app is active or not Notifications.setNotificationHandler({ @@ -106,7 +109,7 @@ export const App: React.FC = () => { | `analyticsEnabled` | boolean | No | Sets the configuration flag that enables or disables Salesforce MarketingCloud Analytics services | | `applicationControlsBadging` | boolean | No | Sets the configuration value which enables or disables application control over badging | | `delayRegistrationUntilContactKeyIsSet` | boolean | No | Sets the configuration value which enables or disables application control over delaying SDK registration until a contact key is set | -| `markNotificationReadOnInboxNotificationOpen` | boolean | No | Sets the configuration value which enables or disables marking inbox notifications as read on open | +| `markNotificationReadOnInboxNotificationOpen` | boolean | No | Sets the configuration value which enables or disables marking inbox notifications as read on open | | `debug` | boolean | No | Enable logging debug messages | # Usage @@ -115,64 +118,67 @@ Various functions, their parameters, return values, and their specific purposes ## Functions -| Function Name | Parameters | Return Type | Description | -| --- | --- | --- | --- | -| `isPushEnabled` | None | `Promise` | Returns a promise that resolves to a boolean indicating whether push notifications are enabled for the user. | -| `enablePush` | None | `Promise` | Returns a promise that resolves when push notifications have been successfully enabled. | -| `disablePush` | None | `Promise` | Returns a promise that resolves when push notifications have been successfully disabled. | -| `getSystemToken` | None | `Promise` | Returns a promise that resolves to a string representing the device's push notification token. | -| `setSystemToken` | `token: string` | `Promise` | Returns a promise that resolves when the device's push notification token has been successfully set. | -| `getAttributes` | None | `Promise>` | Returns a promise that resolves to an object representing the user's attributes. | -| `setAttribute` | `key: string`, `value: string` | `Promise` | Returns a promise that resolves when an attribute has been successfully set for the user. | -| `clearAttribute` | `key: string` | `Promise` | Returns a promise that resolves when an attribute has been successfully cleared for the user. | -| `addTag` | `tag: string` | `Promise` | Returns a promise that resolves when a tag has been successfully added for the user. | -| `removeTag` | `tag: string` | `Promise` | Returns a promise that resolves when a tag has been successfully removed for the user. | -| `getTags` | None | `Promise` | Returns a promise that resolves to an array of strings representing the user's tags. | -| `setContactKey` | `contactKey: string` | `Promise` | Returns a promise that resolves when the user's contact key has been successfully set. | -| `getContactKey` | None | `Promise` | Returns a promise that resolves to a string representing the user's contact key. | -| `getSdkState` | None | `Promise>` | Returns a promise that resolves to an object representing the current state of the SDK. | -| `track` | `name: string`, `attributes: Record` | `Promise` | Returns a promise that resolves when a custom event has been successfully tracked. | -| `deleteMessage` | `messageId: string` | `Promise` | Returns a promise that resolves when a specific inbox message has been successfully deleted. | -| `getDeletedMessageCount` | None | `Promise` | Returns a promise that resolves to a number representing the total number of deleted inbox messages. | -| `getDeletedMessages` | None | `Promise` | Returns a promise that resolves to an array of `InboxMessage` objects representing the deleted inbox messages. | -| `getMessageCount` | None | `Promise` | Returns a promise that resolves to a number representing the total number of inbox messages. | -| `getMessages` | None | `Promise` | Returns a promise that resolves to an array of `InboxMessage` objects representing the inbox messages. | -| `getReadMessageCount` | None | `Promise` | Returns a promise that resolves to a number representing the total number of read inbox messages. | -| `getReadMessages` | None | `Promise` | Returns a promise that resolves to an array of `InboxMessage` objects representing the read inbox messages. | -| `trackMessageOpened` | `messageId`: string | Promise | Returns a promise that resolves to true when inbox open event successfully triggered on message. | - +| Function Name | Parameters | Return Type | Description | +| ------------------------ | ---------------------------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------- | +| `isPushEnabled` | None | `Promise` | Returns a promise that resolves to a boolean indicating whether push notifications are enabled for the user. | +| `enablePush` | None | `Promise` | Returns a promise that resolves when push notifications have been successfully enabled. | +| `disablePush` | None | `Promise` | Returns a promise that resolves when push notifications have been successfully disabled. | +| `getSystemToken` | None | `Promise` | Returns a promise that resolves to a string representing the device's push notification token. | +| `setSystemToken` | `token: string` | `Promise` | Returns a promise that resolves when the device's push notification token has been successfully set. | +| `getAttributes` | None | `Promise>` | Returns a promise that resolves to an object representing the user's attributes. | +| `setAttribute` | `key: string`, `value: string` | `Promise` | Returns a promise that resolves when an attribute has been successfully set for the user. | +| `clearAttribute` | `key: string` | `Promise` | Returns a promise that resolves when an attribute has been successfully cleared for the user. | +| `addTag` | `tag: string` | `Promise` | Returns a promise that resolves when a tag has been successfully added for the user. | +| `removeTag` | `tag: string` | `Promise` | Returns a promise that resolves when a tag has been successfully removed for the user. | +| `getTags` | None | `Promise` | Returns a promise that resolves to an array of strings representing the user's tags. | +| `setContactKey` | `contactKey: string` | `Promise` | Returns a promise that resolves when the user's contact key has been successfully set. | +| `getContactKey` | None | `Promise` | Returns a promise that resolves to a string representing the user's contact key. | +| `getSdkState` | None | `Promise>` | Returns a promise that resolves to an object representing the current state of the SDK. | +| `track` | `name: string`, `attributes: Record` | `Promise` | Returns a promise that resolves when a custom event has been successfully tracked. | +| `deleteMessage` | `messageId: string` | `Promise` | Returns a promise that resolves when a specific inbox message has been successfully deleted. | +| `getDeletedMessageCount` | None | `Promise` | Returns a promise that resolves to a number representing the total number of deleted inbox messages. | +| `getDeletedMessages` | None | `Promise` | Returns a promise that resolves to an array of `InboxMessage` objects representing the deleted inbox messages. | +| `getMessageCount` | None | `Promise` | Returns a promise that resolves to a number representing the total number of inbox messages. | +| `getMessages` | None | `Promise` | Returns a promise that resolves to an array of `InboxMessage` objects representing the inbox messages. | +| `getReadMessageCount` | None | `Promise` | Returns a promise that resolves to a number representing the total number of read inbox messages. | +| `getReadMessages` | None | `Promise` | Returns a promise that resolves to an array of `InboxMessage` objects representing the read inbox messages. | +| `trackMessageOpened` | `messageId`: string | Promise | Returns a promise that resolves to true when inbox open event successfully triggered on message. | ## Add event listener + Available event listeners: -| Function | Parameters | Description | -| --- | --- | --- | -| `addLogListener` | `listener: (event: LogEventPayload) => void` | Adds a listener function to the `onLog` event, which is triggered when a new log event is generated. | -| `addInboxResponseListener` | `listener: (event: InboxResponsePayload) => void` | Adds a listener function to the `onInboxResponse` event, which is triggered when a new inbox response is received. | +| Function | Parameters | Description | +| ------------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | +| `addLogListener` | `listener: (event: LogEventPayload) => void` | Adds a listener function to the `onLog` event, which is triggered when a new log event is generated. | +| `addInboxResponseListener` | `listener: (event: InboxResponsePayload) => void` | Adds a listener function to the `onInboxResponse` event, which is triggered when a new inbox response is received. | | `addRegistrationResponseSucceededListener` | `listener: (event: RegistrationResponseSucceededPayload) => void` | Adds a listener function to the `onRegistrationResponseSucceeded` event, which is triggered when SDK successfully registers with backend. | ```typescript // listeners being used in a useEffect hook. useEffect(() => { - const logSubscription = addLogListener((logEvent: LogEventPayload) => { - // Do something with logEvent - }) + const logSubscription = addLogListener((logEvent: LogEventPayload) => { + // Do something with logEvent + }) - const inboxSubscription = addInboxResponseListener((inboxEvent: InboxResponsePayload) => { - // Do something with inboxEvent - }) + const inboxSubscription = addInboxResponseListener( + (inboxEvent: InboxResponsePayload) => { + // Do something with inboxEvent + } + ) - const registrationSubscription = MarketingCloud.addRegistrationResponseSucceededListener((registrationEvent: RegistrationResponseSucceededPayload) => { - // Do something with registrationEvent - }) + const registrationSubscription = + MarketingCloud.addRegistrationResponseSucceededListener( + (registrationEvent: RegistrationResponseSucceededPayload) => { + // Do something with registrationEvent + } + ) - return () => { - logSubscription.remove() - inboxSubscription.remove() - registrationSubscription.remove() - } + return () => { + logSubscription.remove() + inboxSubscription.remove() + registrationSubscription.remove() + } }, []) ``` - - diff --git a/android/src/main/java/expo/modules/marketingcloudsdk/ExpoMarketingCloudSdkApplicationLifecycleListener.kt b/android/src/main/java/expo/modules/marketingcloudsdk/ExpoMarketingCloudSdkApplicationLifecycleListener.kt index 389fe81..9450faa 100644 --- a/android/src/main/java/expo/modules/marketingcloudsdk/ExpoMarketingCloudSdkApplicationLifecycleListener.kt +++ b/android/src/main/java/expo/modules/marketingcloudsdk/ExpoMarketingCloudSdkApplicationLifecycleListener.kt @@ -35,6 +35,7 @@ class ExpoMarketingCloudSdkApplicationLifecycleListener : ApplicationLifecycleLi SFMCSdk.configure(application, SFMCSdkModuleConfig.build { pushModuleConfig = MarketingCloudConfig.builder().apply { setApplicationId(getAppId(application)) + if(getMid(application) != "") setMid(getMid(application)) setAccessToken(getAccessToken(application)) setAnalyticsEnabled(getAnalyticsEnabled(application)) setMarketingCloudServerUrl(getServerUrl(application)) @@ -54,6 +55,7 @@ class ExpoMarketingCloudSdkApplicationLifecycleListener : ApplicationLifecycleLi private fun getDebug(context: Context): Boolean = context.resources.getString(R.string.expo_marketingcloudsdk_debug) == "true" private fun getAppId(context: Context): String = context.resources.getString(R.string.expo_marketingcloudsdk_app_id) + private fun getMid(context: Context): String = context.resources.getString(R.string.expo_marketingcloudsdk_mid) private fun getAccessToken(context: Context): String = context.resources.getString(R.string.expo_marketingcloudsdk_access_token) private fun getServerUrl(context: Context): String = context.resources.getString(R.string.expo_marketingcloudsdk_server_url) private fun getSenderId(context: Context): String = context.resources.getString(R.string.expo_marketingcloudsdk_sender_id) diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml index bfe3c33..b3d2739 100644 --- a/android/src/main/res/values/strings.xml +++ b/android/src/main/res/values/strings.xml @@ -2,6 +2,7 @@ false + diff --git a/package.json b/package.json index a5b21f0..9b5fa23 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "name": "@allboatsrise/expo-marketingcloudsdk", - "author": "All Boats Rise Inc.", - "version": "51.0.5", + "name": "@hi3g-access/expo-marketingcloudsdk", + "author": "Hi3G Access AB", + "version": "51.0.6", "license": "MIT", "description": "Expo module for Salesforce Marketing Cloud SDK", - "homepage": "https://github.com/allboatsrise/expo-marketingcloudsdk", + + "homepage": "https://github.com/hi3g-access/expo-marketingcloudsdk", "keywords": [ "react-native", "expo", @@ -17,7 +18,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/allboatsrise/expo-marketingcloudsdk.git" + "url": "https://github.com/hi3g-access/expo-marketingcloudsdk.git" }, "main": "build/index.js", "types": "build/index.d.ts", @@ -60,5 +61,8 @@ "expo": { "optional": true } + }, + "publishConfig": { + "@hi3g-access:registry": "https://npm.pkg.github.com" } } diff --git a/plugin/src/android/index.ts b/plugin/src/android/index.ts index 1b22105..3fdee86 100644 --- a/plugin/src/android/index.ts +++ b/plugin/src/android/index.ts @@ -48,6 +48,7 @@ const withConfiguration: ConfigPlugin = (conf // XML represented as JSON { $: { name: 'expo_marketingcloudsdk_debug', translatable: 'false' }, _: props.debug ? 'true' : 'false' }, { $: { name: 'expo_marketingcloudsdk_app_id', translatable: 'false' }, _: props.appId }, + { $: { name: 'expo_marketingcloudsdk_mid', translatable: 'false' }, _: props.mid ?? '' }, { $: { name: 'expo_marketingcloudsdk_access_token', translatable: 'false' }, _: props.accessToken }, { $: { name: 'expo_marketingcloudsdk_server_url', translatable: 'false' }, _: props.serverUrl }, { $: { name: 'expo_marketingcloudsdk_sender_id', translatable: 'false' }, _: props.senderId ?? '' },