From cf9cdee31a74e58b07c76be94c30e0aea36a3aa8 Mon Sep 17 00:00:00 2001 From: Sahand Seifi Date: Fri, 24 Oct 2025 12:20:30 -0400 Subject: [PATCH 1/4] Slack helper functions --- lib/client.ts | 67 ++++++++++++++++++++++++++++++++++++++++++++++- lib/interfaces.ts | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/lib/client.ts b/lib/client.ts index 1615660..d2665d0 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -7,6 +7,7 @@ import { DeliveryOptionsForEmail, DeliveryOptionsForInappWeb, PostUserRequest, + User, UserAccountMetadata, WS_REGION } from './interfaces'; @@ -33,6 +34,9 @@ type NotificationAPIClientSDKConfig = { // Debug mode: debug: boolean; + + // SDK Dev Mode: + sdkDevMode: boolean; }; const defaultConfig: NotificationAPIClientSDKConfig = { @@ -47,7 +51,8 @@ const defaultConfig: NotificationAPIClientSDKConfig = { ).toISOString(), onNewInAppNotifications: undefined, keepWebSocketAliveForSeconds: 24 * 60 * 60, // 24 hours - debug: false + debug: false, + sdkDevMode: false }; type NotificationAPIClientSDK = { @@ -119,6 +124,19 @@ type NotificationAPIClientSDK = { getUserAccountMetadata(): Promise<{ userAccountMetadata: UserAccountMetadata; }>; + user: { + get: () => Promise; + }; + slack: { + getOAuthUrl: (props?: { destinationUrl?: string }) => string; + getChannels: () => Promise<{ + channels: { + id: string; + name: string; + }[]; + }>; + setChannel: (channelId: string) => Promise; + }; }; export const NotificationAPIClientSDK: NotificationAPIClientSDK = { @@ -395,5 +413,52 @@ export const NotificationAPIClientSDK: NotificationAPIClientSDK = { }, getUserAccountMetadata: async () => { return NotificationAPIClientSDK.rest.getUserAccountMetadata(); + }, + + user: { + get: async () => { + return NotificationAPIClientSDK.rest.generic('GET', '') as Promise; + } + }, + + slack: { + getOAuthUrl: (props?: { destinationUrl?: string }) => { + const sdkDevMode = NotificationAPIClientSDK.config.sdkDevMode; + const domain = sdkDevMode + ? 'localhost:3001' + : NotificationAPIClientSDK.config.host.replace('api.', 'app.'); + // if no redirectUri is provided, use the current page's URL + const destination = props?.destinationUrl || window.location.href; + + const state = encodeURIComponent( + JSON.stringify({ + destination, + userId: NotificationAPIClientSDK.config.userId, + clientId: NotificationAPIClientSDK.config.clientId, + hashedUserId: NotificationAPIClientSDK.config.hashedUserId + }) + ); + + const url = + 'https://slack.com/oauth/v2/authorize?' + + 'client_id=1146598856352.8825220259395' + + '&scope=chat:write,channels:read,channels:join,chat:write.customize,chat:write.public,groups:read,im:read,users:read' + + `&redirect_uri=https://${domain}/slack/oauth/callback` + + `&state=${state}`; + return url; + }, + getChannels: async () => { + const response = await NotificationAPIClientSDK.rest.generic( + 'GET', + 'slack/channels' + ); + console.log(response); + return response; + }, + setChannel: async (channelId: string) => { + return NotificationAPIClientSDK.identify({ + slackChannel: channelId + }); + } } }; diff --git a/lib/interfaces.ts b/lib/interfaces.ts index 2068359..4b74e0c 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -178,8 +178,64 @@ export interface User { lastSeenTime?: string; createdAt?: string; updatedAt?: string; + slackChannel?: string; + slackToken?: OauthV2AccessResponse; } +interface WebAPICallResult { + ok: boolean; + error?: string; + response_metadata?: { + warnings?: string[]; + next_cursor?: string; + scopes?: string[]; + acceptedScopes?: string[]; + retryAfter?: number; + messages?: string[]; + }; +} + +interface AuthedUser { + access_token?: string; + expires_in?: number; + id?: string; + refresh_token?: string; + scope?: string; + token_type?: string; +} + +interface Enterprise { + id?: string; + name?: string; +} + +export interface IncomingWebhook { + channel?: string; + channel_id?: string; + configuration_url?: string; + url?: string; +} + +type OauthV2AccessResponse = WebAPICallResult & { + access_token?: string; + app_id?: string; + authed_user?: AuthedUser; + bot_user_id?: string; + enterprise?: Enterprise; + error?: string; + expires_in?: number; + incoming_webhook?: IncomingWebhook; + is_enterprise_install?: boolean; + needed?: string; + ok?: boolean; + provided?: string; + refresh_token?: string; + scope?: string; + team?: Enterprise; + token_type?: string; + warning?: string; +}; + export type PostUserRequest = Omit< Partial, 'lastSeenTime' | 'createdAt' | 'updatedAt' From ee38dc863998f8ddf90675103995c66e70823a86 Mon Sep 17 00:00:00 2001 From: Sahand Seifi Date: Fri, 24 Oct 2025 12:22:13 -0400 Subject: [PATCH 2/4] Update README.md to clarify versioning instructions and ensure consistent formatting --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b6408c..bc26469 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # notificationapi-js-core With [NotificationAPI](https://www.notificationapi.com), software developers can implement any kind of notifications into their app in a matter of minutes. -notificationapi-js-core focuses on providing headless UI support to Vanilla JavaScript users looking to use our infrastructure within their own designs. +notificationapi-js-core focuses on providing headless UI support to Vanilla JavaScript users looking to use our infrastructure within their own designs. # Docs @@ -22,3 +22,15 @@ npm run test ``` 100% code coverage required. + +Update the version: + +``` +npm version major|minor|patch +``` + +Major: for breaking changes +Minor: for new features +Patch: for bug fixes + +The pipeline will automatically build and publish the package to npm. From 247db9fc2444250973d56290a8dd2b78aa8aec63 Mon Sep 17 00:00:00 2001 From: Sahand Seifi Date: Fri, 24 Oct 2025 12:22:50 -0400 Subject: [PATCH 3/4] 1.0.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7bf298a..32f49b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@notificationapi/core", - "version": "0.0.17", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@notificationapi/core", - "version": "0.0.17", + "version": "1.0.0", "devDependencies": { "@types/jest": "^29.5.3", "@types/node": "^20.14.10", diff --git a/package.json b/package.json index 356e9e3..7e27bcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@notificationapi/core", - "version": "0.0.17", + "version": "1.0.0", "type": "module", "main": "dist/main.js", "types": "dist/main.d.ts", From 0f74871c4fd0b2cc151ffceda628957a7629391b Mon Sep 17 00:00:00 2001 From: Sahand Seifi Date: Fri, 24 Oct 2025 15:15:10 -0400 Subject: [PATCH 4/4] Remove unnecessary log --- lib/client.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/client.ts b/lib/client.ts index d2665d0..7ef0ea3 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -452,7 +452,6 @@ export const NotificationAPIClientSDK: NotificationAPIClientSDK = { 'GET', 'slack/channels' ); - console.log(response); return response; }, setChannel: async (channelId: string) => {