@knocklabs/client 0.8.15 → 0.8.16
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 +9 -27
- package/dist/cjs/api.js +33 -56
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/clients/feed/feed.js +492 -624
- package/dist/cjs/clients/feed/feed.js.map +1 -1
- package/dist/cjs/clients/feed/index.js +1 -10
- package/dist/cjs/clients/feed/index.js.map +1 -1
- package/dist/cjs/clients/feed/interfaces.js.map +1 -1
- package/dist/cjs/clients/feed/store.js +4 -15
- package/dist/cjs/clients/feed/store.js.map +1 -1
- package/dist/cjs/clients/feed/types.js.map +1 -1
- package/dist/cjs/clients/feed/utils.js +0 -5
- package/dist/cjs/clients/feed/utils.js.map +1 -1
- package/dist/cjs/clients/preferences/index.js +216 -249
- package/dist/cjs/clients/preferences/index.js.map +1 -1
- package/dist/cjs/clients/preferences/interfaces.js.map +1 -1
- package/dist/cjs/clients/users/index.js +134 -61
- package/dist/cjs/clients/users/index.js.map +1 -1
- package/dist/cjs/clients/users/interfaces.js +6 -0
- package/dist/cjs/clients/users/interfaces.js.map +1 -0
- package/dist/cjs/index.js +3 -23
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces.js.map +1 -1
- package/dist/cjs/knock.js +9 -22
- package/dist/cjs/knock.js.map +1 -1
- package/dist/cjs/networkStatus.js +3 -6
- package/dist/cjs/networkStatus.js.map +1 -1
- package/dist/esm/api.js +9 -21
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/clients/feed/feed.js +69 -149
- package/dist/esm/clients/feed/feed.js.map +1 -1
- package/dist/esm/clients/feed/index.js +0 -5
- package/dist/esm/clients/feed/index.js.map +1 -1
- package/dist/esm/clients/feed/interfaces.js.map +1 -1
- package/dist/esm/clients/feed/store.js +2 -8
- package/dist/esm/clients/feed/store.js.map +1 -1
- package/dist/esm/clients/feed/types.js.map +1 -1
- package/dist/esm/clients/feed/utils.js +0 -1
- package/dist/esm/clients/feed/utils.js.map +1 -1
- package/dist/esm/clients/preferences/index.js +35 -25
- package/dist/esm/clients/preferences/index.js.map +1 -1
- package/dist/esm/clients/preferences/interfaces.js.map +1 -1
- package/dist/esm/clients/users/index.js +47 -16
- package/dist/esm/clients/users/index.js.map +1 -1
- package/dist/esm/clients/users/interfaces.js +2 -0
- package/dist/esm/clients/users/interfaces.js.map +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/knock.js +8 -23
- package/dist/esm/knock.js.map +1 -1
- package/dist/esm/networkStatus.js +3 -5
- package/dist/esm/networkStatus.js.map +1 -1
- package/dist/types/api.d.ts +1 -1
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/clients/feed/feed.d.ts +1 -1
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/interfaces.d.ts +2 -1
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/dist/types/clients/feed/types.d.ts +10 -10
- package/dist/types/clients/feed/types.d.ts.map +1 -1
- package/dist/types/clients/preferences/index.d.ts +27 -0
- package/dist/types/clients/preferences/index.d.ts.map +1 -1
- package/dist/types/clients/preferences/interfaces.d.ts +7 -4
- package/dist/types/clients/preferences/interfaces.d.ts.map +1 -1
- package/dist/types/clients/users/index.d.ts +8 -9
- package/dist/types/clients/users/index.d.ts.map +1 -1
- package/dist/types/clients/users/interfaces.d.ts +8 -0
- package/dist/types/clients/users/interfaces.d.ts.map +1 -0
- package/dist/types/interfaces.d.ts +6 -2
- package/dist/types/interfaces.d.ts.map +1 -1
- package/package.json +16 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/clients/feed/feed.ts"],"names":["EventEmitter2","EventEmitter","createStore","isRequestInFlight","NetworkStatus","feedClientDefaults","archived","Feed","constructor","knock","feedId","options","apiClient","client","userFeedId","buildUserFeedId","store","broadcaster","wildcard","delimiter","defaultOptions","socket","channel","on","resp","onNewMessageReceived","broadcastChannel","self","BroadcastChannel","teardown","leave","off","removeAllListeners","destroy","close","listenForUpdates","isConnected","connect","includes","state","join","__experimentalCrossBrowserUpdates","onmessage","e","data","type","fetch","eventName","callback","getState","markAsSeen","itemOrItems","now","Date","toISOString","optimisticallyPerformStatusUpdate","seen_at","makeStatusUpdate","markAllAsSeen","setState","metadata","items","isViewingOnlyUnseen","status","resetStore","total_count","unseen_count","setMetadata","attrs","itemIds","map","item","id","setItemAttrs","result","makeBulkStatusUpdate","emit","broadcastOverChannel","markAsUnseen","markAsRead","read_at","markAllAsRead","isViewingOnlyUnread","unread_count","markAsUnread","markAsInteracted","interacted_at","markAsArchived","shouldOptimisticallyRemoveItems","normalizedItems","Array","isArray","unseenCount","filter","i","length","unreadCount","updatedMetadata","entriesToSet","setResult","entries","meta","page_info","pageInfo","archived_at","markAllAsArchived","markAsUnarchived","networkStatus","setNetworkStatus","__loadingType","loading","queryParams","undefined","__fetchSource","makeRequest","method","url","userId","params","statusCode","body","error","response","before","opts","shouldSetPage","shouldAppend","after","broadcast","feedEventType","eventPayload","event","fetchNextPage","fetchMore","currentHead","__cursor","badgeCountAttr","itemsToUpdate","direction","startsWith","Math","max","message_ids","user_ids","engagement_status","has_tenant","tenants","tenant","payload","stringifiedPayload","JSON","parse","stringify","postMessage","console","warn"],"mappings":";;;;;;;AAEA,SAASA,aAAa,IAAIC,YAA1B,QAA8C,eAA9C;AAEA,OAAOC,WAAP,MAAwB,SAAxB;AAmBA,SAASC,iBAAT,EAA4BC,aAA5B,QAAiD,qBAAjD;AAWA;AACA,IAAMC,kBAAuD,GAAG;AAC9DC,EAAAA,QAAQ,EAAE;AADoD,CAAhE;;AAIA,MAAMC,IAAN,CAAW;AAQT;AAGAC,EAAAA,WAAW,CACAC,KADA,EAEAC,MAFA,EAGTC,OAHS,EAIT;AAAA,SAHSF,KAGT,GAHSA,KAGT;AAAA,SAFSC,MAET,GAFSA,MAET;;AAAA;;AAAA;;AAAA;;AAA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AC1G,MAAvB,4BAA+CmC,IAA/C,CAFmC;AAGtCD,QAAAA,IAAI,EAAEjC;AAHgC,OAA3B,CAAb;AAlBoE;AAuBrE;;AAEOkE,EAAAA,oBAAoB,CAAChC,IAAD,EAAeuG,OAAf,EAA6B;AACvD;AACA,QAAI,CAAC,KAAK1H,gBAAV,EAA4B;AAC1B;AACD,KAJsD,CAMvD;AACA;;;AACA,QAAI;AACF,UAAM2H,kBAAkB,GAAGC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,SAAL,CAAeJ,OAAf,CAAX,CAA3B;AAEA,WAAK1H,gBAAL,CAAsB+H,WAAtB,CAAkC;AAChC5G,QAAAA,IADgC;AAEhCuG,QAAAA,OAAO,EAAEC;AAFuB,OAAlC;AAID,KAPD,CAOE,OAAO1G,CAAP,EAAU;AACV+G,MAAAA,OAAO,CAACC,IAAR,+BAAoC9G,IAApC,0BAAwDF,CAAxD;AACD;AACF;;AArnBQ;;AAwnBX,eAAepC,IAAf","sourcesContent":["import { Channel } from \"phoenix\";\nimport { StoreApi } from \"zustand\";\nimport { EventEmitter2 as EventEmitter } from \"eventemitter2\";\nimport ApiClient from \"../../api\";\nimport createStore from \"./store\";\nimport {\n BindableFeedEvent,\n FeedMessagesReceivedPayload,\n FeedEventCallback,\n FeedEvent,\n FeedItemOrItems,\n FeedStoreState,\n FeedEventPayload,\n FeedRealTimeCallback,\n} from \"./types\";\nimport {\n FeedItem,\n FeedClientOptions,\n FetchFeedOptions,\n FeedResponse,\n FeedMetadata,\n} from \"./interfaces\";\nimport Knock from \"../../knock\";\nimport { isRequestInFlight, NetworkStatus } from \"../../networkStatus\";\n\nexport type Status =\n | \"seen\"\n | \"read\"\n | \"interacted\"\n | \"archived\"\n | \"unseen\"\n | \"unread\"\n | \"unarchived\";\n\n// Default options to apply\nconst feedClientDefaults: Pick<FeedClientOptions, \"archived\"> = {\n archived: \"exclude\",\n};\n\nclass Feed {\n private apiClient: ApiClient;\n private userFeedId: string;\n private channel: Channel | undefined;\n private broadcaster: EventEmitter;\n private defaultOptions: FeedClientOptions;\n private broadcastChannel: BroadcastChannel | null;\n\n // The raw store instance, used for binding in React and other environments\n public store: StoreApi<FeedStoreState>;\n\n constructor(\n readonly knock: Knock,\n readonly feedId: string,\n options: FeedClientOptions,\n ) {\n this.apiClient = knock.client();\n this.feedId = feedId;\n this.userFeedId = this.buildUserFeedId();\n this.store = createStore();\n this.broadcaster = new EventEmitter({ wildcard: true, delimiter: \".\" });\n this.defaultOptions = { ...feedClientDefaults, ...options };\n\n // In server environments we might not have a socket connection\n if (this.apiClient.socket) {\n this.channel = this.apiClient.socket.channel(\n `feeds:${this.userFeedId}`,\n this.defaultOptions,\n );\n\n this.channel.on(\"new-message\", (resp) => this.onNewMessageReceived(resp));\n }\n\n // Attempt to bind to listen to other events from this feed in different tabs\n // Note: here we ensure `self` is available (it's not in server rendered envs)\n this.broadcastChannel =\n typeof self !== \"undefined\" && \"BroadcastChannel\" in self\n ? new BroadcastChannel(`knock:feed:${this.userFeedId}`)\n : null;\n }\n\n /**\n * Cleans up a feed instance by destroying the store and disconnecting\n * an open socket connection.\n */\n teardown() {\n if (this.channel) {\n this.channel.leave();\n this.channel.off(\"new-message\");\n }\n\n this.broadcaster.removeAllListeners();\n this.store.destroy();\n\n if (this.broadcastChannel) {\n this.broadcastChannel.close();\n }\n }\n\n /*\n Initializes a real-time connection to Knock, connecting the websocket for the\n current ApiClient instance if the socket is not already connected.\n */\n listenForUpdates() {\n // Connect the socket only if we don't already have a connection\n if (this.apiClient.socket && !this.apiClient.socket.isConnected()) {\n this.apiClient.socket.connect();\n }\n\n // Only join the channel if we're not already in a joining state\n if (this.channel && [\"closed\", \"errored\"].includes(this.channel.state)) {\n this.channel.join();\n }\n\n // Opt into receiving updates from _other tabs for the same user / feed_ via the broadcast\n // channel (iff it's enabled and exists)\n if (\n this.broadcastChannel &&\n this.defaultOptions.__experimentalCrossBrowserUpdates === true\n ) {\n this.broadcastChannel.onmessage = (e) => {\n switch (e.data.type) {\n case \"items:archived\":\n case \"items:unarchived\":\n case \"items:seen\":\n case \"items:unseen\":\n case \"items:read\":\n case \"items:unread\":\n case \"items:all_read\":\n case \"items:all_seen\":\n case \"items:all_archived\":\n // When items are updated in any other tab, simply refetch to get the latest state\n // to make sure that the state gets updated accordingly. In the future here we could\n // maybe do this optimistically without the fetch.\n return this.fetch();\n break;\n default:\n return null;\n }\n };\n }\n }\n\n /* Binds a handler to be invoked when event occurs */\n on(\n eventName: BindableFeedEvent,\n callback: FeedEventCallback | FeedRealTimeCallback,\n ) {\n this.broadcaster.on(eventName, callback);\n }\n\n off(\n eventName: BindableFeedEvent,\n callback: FeedEventCallback | FeedRealTimeCallback,\n ) {\n this.broadcaster.off(eventName, callback);\n }\n\n getState() {\n return this.store.getState();\n }\n\n async markAsSeen(itemOrItems: FeedItemOrItems) {\n const now = new Date().toISOString();\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"seen\",\n { seen_at: now },\n \"unseen_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"seen\");\n }\n\n async markAllAsSeen() {\n // To mark all of the messages as seen we:\n // 1. Optimistically update *everything* we have in the store\n // 2. We decrement the `unseen_count` to zero optimistically\n // 3. We issue the API call to the endpoint\n //\n // Note: there is the potential for a race condition here because the bulk\n // update is an async method, so if a new message comes in during this window before\n // the update has been processed we'll effectively reset the `unseen_count` to be what it was.\n //\n // Note: here we optimistically handle the case whereby the feed is scoped to show only `unseen`\n // items by removing everything from view.\n const { getState, setState } = this.store;\n const { metadata, items } = getState();\n\n const isViewingOnlyUnseen = this.defaultOptions.status === \"unseen\";\n\n // If we're looking at the unseen view, then we want to remove all of the items optimistically\n // from the store given that nothing should be visible. We do this by resetting the store state\n // and setting the current metadata counts to 0\n if (isViewingOnlyUnseen) {\n setState((store) =>\n store.resetStore({\n ...metadata,\n total_count: 0,\n unseen_count: 0,\n }),\n );\n } else {\n // Otherwise we want to update the metadata and mark all of the items in the store as seen\n setState((store) => store.setMetadata({ ...metadata, unseen_count: 0 }));\n\n const attrs = { seen_at: new Date().toISOString() };\n const itemIds = items.map((item) => item.id);\n\n setState((store) => store.setItemAttrs(itemIds, attrs));\n }\n\n // Issue the API request to the bulk status change API\n const result = await this.makeBulkStatusUpdate(\"seen\");\n\n this.broadcaster.emit(`items:all_seen`, { items });\n this.broadcastOverChannel(`items:all_seen`, { items });\n\n return result;\n }\n\n async markAsUnseen(itemOrItems: FeedItemOrItems) {\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"unseen\",\n { seen_at: null },\n \"unseen_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"unseen\");\n }\n\n async markAsRead(itemOrItems: FeedItemOrItems) {\n const now = new Date().toISOString();\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"read\",\n { read_at: now },\n \"unread_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"read\");\n }\n\n async markAllAsRead() {\n // To mark all of the messages as read we:\n // 1. Optimistically update *everything* we have in the store\n // 2. We decrement the `unread_count` to zero optimistically\n // 3. We issue the API call to the endpoint\n //\n // Note: there is the potential for a race condition here because the bulk\n // update is an async method, so if a new message comes in during this window before\n // the update has been processed we'll effectively reset the `unread_count` to be what it was.\n //\n // Note: here we optimistically handle the case whereby the feed is scoped to show only `unread`\n // items by removing everything from view.\n const { getState, setState } = this.store;\n const { metadata, items } = getState();\n\n const isViewingOnlyUnread = this.defaultOptions.status === \"unread\";\n\n // If we're looking at the unread view, then we want to remove all of the items optimistically\n // from the store given that nothing should be visible. We do this by resetting the store state\n // and setting the current metadata counts to 0\n if (isViewingOnlyUnread) {\n setState((store) =>\n store.resetStore({\n ...metadata,\n total_count: 0,\n unread_count: 0,\n }),\n );\n } else {\n // Otherwise we want to update the metadata and mark all of the items in the store as seen\n setState((store) => store.setMetadata({ ...metadata, unread_count: 0 }));\n\n const attrs = { read_at: new Date().toISOString() };\n const itemIds = items.map((item) => item.id);\n\n setState((store) => store.setItemAttrs(itemIds, attrs));\n }\n\n // Issue the API request to the bulk status change API\n const result = await this.makeBulkStatusUpdate(\"read\");\n\n this.broadcaster.emit(`items:all_read`, { items });\n this.broadcastOverChannel(`items:all_read`, { items });\n\n return result;\n }\n\n async markAsUnread(itemOrItems: FeedItemOrItems) {\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"unread\",\n { read_at: null },\n \"unread_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"unread\");\n }\n\n async markAsInteracted(itemOrItems: FeedItemOrItems) {\n const now = new Date().toISOString();\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"interacted\",\n {\n read_at: now,\n interacted_at: now,\n },\n \"unread_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"interacted\");\n }\n\n /*\n Marking one or more items as archived should:\n\n - Decrement the badge count for any unread / unseen items\n - Remove the item from the feed list when the `archived` flag is \"exclude\" (default)\n\n TODO: how do we handle rollbacks?\n */\n async markAsArchived(itemOrItems: FeedItemOrItems) {\n const { getState, setState } = this.store;\n const state = getState();\n\n const shouldOptimisticallyRemoveItems =\n this.defaultOptions.archived === \"exclude\";\n\n const normalizedItems = Array.isArray(itemOrItems)\n ? itemOrItems\n : [itemOrItems];\n\n const itemIds: string[] = normalizedItems.map((item) => item.id);\n\n /*\n In the code here we want to optimistically update counts and items\n that are persisted such that we can display updates immediately on the feed\n without needing to make a network request.\n\n Note: right now this does *not* take into account offline handling or any extensive retry\n logic, so rollbacks aren't considered. That probably needs to be a future consideration for\n this library.\n\n Scenarios to consider:\n\n ## Feed scope to archived *only*\n\n - Counts should not be decremented\n - Items should not be removed\n\n ## Feed scoped to exclude archived items (the default)\n\n - Counts should be decremented\n - Items should be removed\n\n ## Feed scoped to include archived items as well\n\n - Counts should not be decremented\n - Items should not be removed\n */\n\n if (shouldOptimisticallyRemoveItems) {\n // If any of the items are unseen or unread, then capture as we'll want to decrement\n // the counts for these in the metadata we have\n const unseenCount = normalizedItems.filter((i) => !i.seen_at).length;\n const unreadCount = normalizedItems.filter((i) => !i.read_at).length;\n\n // Build the new metadata\n const updatedMetadata = {\n ...state.metadata,\n total_count: state.metadata.total_count - normalizedItems.length,\n unseen_count: state.metadata.unseen_count - unseenCount,\n unread_count: state.metadata.unread_count - unreadCount,\n };\n\n // Remove the archiving entries\n const entriesToSet = state.items.filter(\n (item) => !itemIds.includes(item.id),\n );\n\n setState((state) =>\n state.setResult({\n entries: entriesToSet,\n meta: updatedMetadata,\n page_info: state.pageInfo,\n }),\n );\n } else {\n // Mark all the entries being updated as archived either way so the state is correct\n state.setItemAttrs(itemIds, { archived_at: new Date().toISOString() });\n }\n\n return this.makeStatusUpdate(itemOrItems, \"archived\");\n }\n\n async markAllAsArchived() {\n // Note: there is the potential for a race condition here because the bulk\n // update is an async method, so if a new message comes in during this window before\n // the update has been processed we'll effectively reset the `unseen_count` to be what it was.\n const { setState, getState } = this.store;\n const { items } = getState();\n\n // Here if we're looking at a feed that excludes all of the archived items by default then we\n // will want to optimistically remove all of the items from the feed as they are now all excluded\n const shouldOptimisticallyRemoveItems =\n this.defaultOptions.archived === \"exclude\";\n\n if (shouldOptimisticallyRemoveItems) {\n // Reset the store to clear out all of items and reset the badge count\n setState((store) => store.resetStore());\n } else {\n // Mark all the entries being updated as archived either way so the state is correct\n setState((store) => {\n const itemIds = items.map((i) => i.id);\n store.setItemAttrs(itemIds, { archived_at: new Date().toISOString() });\n });\n }\n\n // Issue the API request to the bulk status change API\n const result = await this.makeBulkStatusUpdate(\"archive\");\n\n this.broadcaster.emit(`items:all_archived`, { items });\n this.broadcastOverChannel(`items:all_archived`, { items });\n\n return result;\n }\n\n async markAsUnarchived(itemOrItems: FeedItemOrItems) {\n this.optimisticallyPerformStatusUpdate(itemOrItems, \"unarchived\", {\n archived_at: null,\n });\n\n return this.makeStatusUpdate(itemOrItems, \"unarchived\");\n }\n\n /* Fetches the feed content, appending it to the store */\n async fetch(options: FetchFeedOptions = {}) {\n const { setState, getState } = this.store;\n const { networkStatus } = getState();\n\n // If there's an existing request in flight, then do nothing\n if (isRequestInFlight(networkStatus)) {\n return;\n }\n\n // Set the loading type based on the request type it is\n setState((store) =>\n store.setNetworkStatus(options.__loadingType ?? NetworkStatus.loading),\n );\n\n // Always include the default params, if they have been set\n const queryParams = {\n ...this.defaultOptions,\n ...options,\n // Unset options that should not be sent to the API\n __loadingType: undefined,\n __fetchSource: undefined,\n __experimentalCrossBrowserUpdates: undefined,\n };\n\n const result = await this.apiClient.makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.knock.userId}/feeds/${this.feedId}`,\n params: queryParams,\n });\n\n if (result.statusCode === \"error\" || !result.body) {\n setState((store) => store.setNetworkStatus(NetworkStatus.error));\n\n return {\n status: result.statusCode,\n data: result.error || result.body,\n };\n }\n\n const response = {\n entries: result.body.entries,\n meta: result.body.meta,\n page_info: result.body.page_info,\n };\n\n if (options.before) {\n const opts = { shouldSetPage: false, shouldAppend: true };\n setState((state) => state.setResult(response, opts));\n } else if (options.after) {\n const opts = { shouldSetPage: true, shouldAppend: true };\n setState((state) => state.setResult(response, opts));\n } else {\n setState((state) => state.setResult(response));\n }\n\n // Legacy `messages.new` event, should be removed in a future version\n this.broadcast(\"messages.new\", response);\n\n // Broadcast the appropriate event type depending on the fetch source\n const feedEventType: FeedEvent =\n options.__fetchSource === \"socket\"\n ? \"items.received.realtime\"\n : \"items.received.page\";\n\n const eventPayload = {\n items: response.entries as FeedItem[],\n metadata: response.meta as FeedMetadata,\n event: feedEventType,\n };\n\n this.broadcast(eventPayload.event, eventPayload);\n\n return { data: response, status: result.statusCode };\n }\n\n async fetchNextPage() {\n // Attempts to fetch the next page of results (if we have any)\n const { getState } = this.store;\n const { pageInfo } = getState();\n\n if (!pageInfo.after) {\n // Nothing more to fetch\n return;\n }\n\n this.fetch({\n after: pageInfo.after,\n __loadingType: NetworkStatus.fetchMore,\n });\n }\n\n private broadcast(\n eventName: FeedEvent,\n data: FeedResponse | FeedEventPayload,\n ) {\n this.broadcaster.emit(eventName, data);\n }\n\n // Invoked when a new real-time message comes in from the socket\n private async onNewMessageReceived({\n metadata,\n }: FeedMessagesReceivedPayload) {\n // Handle the new message coming in\n const { getState, setState } = this.store;\n const { items } = getState();\n const currentHead: FeedItem | undefined = items[0];\n // Optimistically set the badge counts\n setState((state) => state.setMetadata(metadata));\n // Fetch the items before the current head (if it exists)\n this.fetch({ before: currentHead?.__cursor, __fetchSource: \"socket\" });\n }\n\n private buildUserFeedId() {\n return `${this.feedId}:${this.knock.userId}`;\n }\n\n private optimisticallyPerformStatusUpdate(\n itemOrItems: FeedItemOrItems,\n type: Status,\n attrs: object,\n badgeCountAttr?: \"unread_count\" | \"unseen_count\",\n ) {\n const { getState, setState } = this.store;\n const normalizedItems = Array.isArray(itemOrItems)\n ? itemOrItems\n : [itemOrItems];\n const itemIds = normalizedItems.map((item) => item.id);\n\n if (badgeCountAttr) {\n const { metadata } = getState();\n\n // We only want to update the counts of items that have not already been counted towards the\n // badge count total to avoid updating the badge count unnecessarily.\n const itemsToUpdate = normalizedItems.filter((item) => {\n switch (type) {\n case \"seen\":\n return item.seen_at === null;\n case \"unseen\":\n return item.seen_at !== null;\n case \"read\":\n case \"interacted\":\n return item.read_at === null;\n case \"unread\":\n return item.read_at !== null;\n default:\n return true;\n }\n });\n\n // Tnis is a hack to determine the direction of whether we're\n // adding or removing from the badge count\n const direction = type.startsWith(\"un\")\n ? itemsToUpdate.length\n : -itemsToUpdate.length;\n\n setState((store) =>\n store.setMetadata({\n ...metadata,\n [badgeCountAttr]: Math.max(0, metadata[badgeCountAttr] + direction),\n }),\n );\n }\n\n // Update the items with the given attributes\n setState((store) => store.setItemAttrs(itemIds, attrs));\n }\n\n private async makeStatusUpdate(itemOrItems: FeedItemOrItems, type: Status) {\n // Always treat items as a batch to use the corresponding batch endpoint\n const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];\n const itemIds = items.map((item) => item.id);\n\n const result = await this.apiClient.makeRequest({\n method: \"POST\",\n url: `/v1/messages/batch/${type}`,\n data: { message_ids: itemIds },\n });\n\n // Emit the event that these items had their statuses changed\n // Note: we do this after the update to ensure that the server event actually completed\n this.broadcaster.emit(`items:${type}`, { items });\n this.broadcastOverChannel(`items:${type}`, { items });\n\n return result;\n }\n\n private async makeBulkStatusUpdate(type: \"seen\" | \"read\" | \"archive\") {\n // The base scope for the call should take into account all of the options currently\n // set on the feed, as well as being scoped for the current user. We do this so that\n // we ONLY make changes to the messages that are currently in view on this feed, and not\n // all messages that exist.\n const options = {\n user_ids: [this.knock.userId],\n engagement_status:\n this.defaultOptions.status !== \"all\"\n ? this.defaultOptions.status\n : undefined,\n archived: this.defaultOptions.archived,\n has_tenant: this.defaultOptions.has_tenant,\n tenants: this.defaultOptions.tenant\n ? [this.defaultOptions.tenant]\n : undefined,\n };\n\n return await this.apiClient.makeRequest({\n method: \"POST\",\n url: `/v1/channels/${this.feedId}/messages/bulk/${type}`,\n data: options,\n });\n }\n\n private broadcastOverChannel(type: string, payload: any) {\n // The broadcastChannel may not be available in non-browser environments\n if (!this.broadcastChannel) {\n return;\n }\n\n // Here we stringify our payload and try and send as JSON such that we\n // don't get any `An object could not be cloned` errors when trying to broadcast\n try {\n const stringifiedPayload = JSON.parse(JSON.stringify(payload));\n\n this.broadcastChannel.postMessage({\n type,\n payload: stringifiedPayload,\n });\n } catch (e) {\n console.warn(`Could not broadcast ${type}, got error: ${e}`);\n }\n }\n}\n\nexport default Feed;\n"],"file":"feed.js"}
|
|
1
|
+
{"version":3,"file":"feed.js","names":["EventEmitter2","EventEmitter","createStore","isRequestInFlight","NetworkStatus","feedClientDefaults","archived","Feed","constructor","knock","feedId","options","_defineProperty","apiClient","client","userFeedId","buildUserFeedId","store","broadcaster","wildcard","delimiter","defaultOptions","_objectSpread","socket","channel","concat","on","resp","onNewMessageReceived","broadcastChannel","self","BroadcastChannel","teardown","leave","off","removeAllListeners","destroy","close","listenForUpdates","isConnected","connect","includes","state","join","__experimentalCrossBrowserUpdates","onmessage","e","data","type","fetch","eventName","callback","getState","markAsSeen","itemOrItems","_this","_asyncToGenerator","now","Date","toISOString","optimisticallyPerformStatusUpdate","seen_at","makeStatusUpdate","markAllAsSeen","_this2","setState","metadata","items","isViewingOnlyUnseen","status","resetStore","total_count","unseen_count","setMetadata","attrs","itemIds","map","item","id","setItemAttrs","result","makeBulkStatusUpdate","emit","broadcastOverChannel","markAsUnseen","_this3","markAsRead","_this4","read_at","markAllAsRead","_this5","isViewingOnlyUnread","unread_count","markAsUnread","_this6","markAsInteracted","_this7","interacted_at","markAsArchived","_this8","shouldOptimisticallyRemoveItems","normalizedItems","Array","isArray","unseenCount","filter","i","length","unreadCount","updatedMetadata","entriesToSet","setResult","entries","meta","page_info","pageInfo","archived_at","markAllAsArchived","_this9","markAsUnarchived","_this10","_arguments","arguments","_this11","undefined","networkStatus","_options$__loadingTyp","setNetworkStatus","__loadingType","loading","queryParams","__fetchSource","makeRequest","method","url","userId","params","statusCode","body","error","response","before","opts","shouldSetPage","shouldAppend","after","broadcast","feedEventType","eventPayload","event","fetchNextPage","_this12","fetchMore","_ref","_this13","currentHead","__cursor","badgeCountAttr","itemsToUpdate","direction","startsWith","Math","max","_this14","message_ids","_this15","user_ids","engagement_status","has_tenant","tenants","tenant","payload","stringifiedPayload","JSON","parse","stringify","postMessage","console","warn"],"sources":["../../../../src/clients/feed/feed.ts"],"sourcesContent":["import { Channel } from \"phoenix\";\nimport { StoreApi } from \"zustand\";\nimport { EventEmitter2 as EventEmitter } from \"eventemitter2\";\nimport ApiClient from \"../../api\";\nimport createStore from \"./store\";\nimport {\n BindableFeedEvent,\n FeedMessagesReceivedPayload,\n FeedEventCallback,\n FeedEvent,\n FeedItemOrItems,\n FeedStoreState,\n FeedEventPayload,\n FeedRealTimeCallback,\n} from \"./types\";\nimport {\n FeedItem,\n FeedClientOptions,\n FetchFeedOptions,\n FeedResponse,\n FeedMetadata,\n} from \"./interfaces\";\nimport Knock from \"../../knock\";\nimport { isRequestInFlight, NetworkStatus } from \"../../networkStatus\";\n\nexport type Status =\n | \"seen\"\n | \"read\"\n | \"interacted\"\n | \"archived\"\n | \"unseen\"\n | \"unread\"\n | \"unarchived\";\n\n// Default options to apply\nconst feedClientDefaults: Pick<FeedClientOptions, \"archived\"> = {\n archived: \"exclude\",\n};\n\nclass Feed {\n private apiClient: ApiClient;\n private userFeedId: string;\n private channel: Channel | undefined;\n private broadcaster: EventEmitter;\n private defaultOptions: FeedClientOptions;\n private broadcastChannel: BroadcastChannel | null;\n\n // The raw store instance, used for binding in React and other environments\n public store: StoreApi<FeedStoreState>;\n\n constructor(\n readonly knock: Knock,\n readonly feedId: string,\n options: FeedClientOptions,\n ) {\n this.apiClient = knock.client();\n this.feedId = feedId;\n this.userFeedId = this.buildUserFeedId();\n this.store = createStore();\n this.broadcaster = new EventEmitter({ wildcard: true, delimiter: \".\" });\n this.defaultOptions = { ...feedClientDefaults, ...options };\n\n // In server environments we might not have a socket connection\n if (this.apiClient.socket) {\n this.channel = this.apiClient.socket.channel(\n `feeds:${this.userFeedId}`,\n this.defaultOptions,\n );\n\n this.channel.on(\"new-message\", (resp) => this.onNewMessageReceived(resp));\n }\n\n // Attempt to bind to listen to other events from this feed in different tabs\n // Note: here we ensure `self` is available (it's not in server rendered envs)\n this.broadcastChannel =\n typeof self !== \"undefined\" && \"BroadcastChannel\" in self\n ? new BroadcastChannel(`knock:feed:${this.userFeedId}`)\n : null;\n }\n\n /**\n * Cleans up a feed instance by destroying the store and disconnecting\n * an open socket connection.\n */\n teardown() {\n if (this.channel) {\n this.channel.leave();\n this.channel.off(\"new-message\");\n }\n\n this.broadcaster.removeAllListeners();\n this.store.destroy();\n\n if (this.broadcastChannel) {\n this.broadcastChannel.close();\n }\n }\n\n /*\n Initializes a real-time connection to Knock, connecting the websocket for the\n current ApiClient instance if the socket is not already connected.\n */\n listenForUpdates() {\n // Connect the socket only if we don't already have a connection\n if (this.apiClient.socket && !this.apiClient.socket.isConnected()) {\n this.apiClient.socket.connect();\n }\n\n // Only join the channel if we're not already in a joining state\n if (this.channel && [\"closed\", \"errored\"].includes(this.channel.state)) {\n this.channel.join();\n }\n\n // Opt into receiving updates from _other tabs for the same user / feed_ via the broadcast\n // channel (iff it's enabled and exists)\n if (\n this.broadcastChannel &&\n this.defaultOptions.__experimentalCrossBrowserUpdates === true\n ) {\n this.broadcastChannel.onmessage = (e) => {\n switch (e.data.type) {\n case \"items:archived\":\n case \"items:unarchived\":\n case \"items:seen\":\n case \"items:unseen\":\n case \"items:read\":\n case \"items:unread\":\n case \"items:all_read\":\n case \"items:all_seen\":\n case \"items:all_archived\":\n // When items are updated in any other tab, simply refetch to get the latest state\n // to make sure that the state gets updated accordingly. In the future here we could\n // maybe do this optimistically without the fetch.\n return this.fetch();\n break;\n default:\n return null;\n }\n };\n }\n }\n\n /* Binds a handler to be invoked when event occurs */\n on(\n eventName: BindableFeedEvent,\n callback: FeedEventCallback | FeedRealTimeCallback,\n ) {\n this.broadcaster.on(eventName, callback);\n }\n\n off(\n eventName: BindableFeedEvent,\n callback: FeedEventCallback | FeedRealTimeCallback,\n ) {\n this.broadcaster.off(eventName, callback);\n }\n\n getState() {\n return this.store.getState();\n }\n\n async markAsSeen(itemOrItems: FeedItemOrItems) {\n const now = new Date().toISOString();\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"seen\",\n { seen_at: now },\n \"unseen_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"seen\");\n }\n\n async markAllAsSeen() {\n // To mark all of the messages as seen we:\n // 1. Optimistically update *everything* we have in the store\n // 2. We decrement the `unseen_count` to zero optimistically\n // 3. We issue the API call to the endpoint\n //\n // Note: there is the potential for a race condition here because the bulk\n // update is an async method, so if a new message comes in during this window before\n // the update has been processed we'll effectively reset the `unseen_count` to be what it was.\n //\n // Note: here we optimistically handle the case whereby the feed is scoped to show only `unseen`\n // items by removing everything from view.\n const { getState, setState } = this.store;\n const { metadata, items } = getState();\n\n const isViewingOnlyUnseen = this.defaultOptions.status === \"unseen\";\n\n // If we're looking at the unseen view, then we want to remove all of the items optimistically\n // from the store given that nothing should be visible. We do this by resetting the store state\n // and setting the current metadata counts to 0\n if (isViewingOnlyUnseen) {\n setState((store) =>\n store.resetStore({\n ...metadata,\n total_count: 0,\n unseen_count: 0,\n }),\n );\n } else {\n // Otherwise we want to update the metadata and mark all of the items in the store as seen\n setState((store) => store.setMetadata({ ...metadata, unseen_count: 0 }));\n\n const attrs = { seen_at: new Date().toISOString() };\n const itemIds = items.map((item) => item.id);\n\n setState((store) => store.setItemAttrs(itemIds, attrs));\n }\n\n // Issue the API request to the bulk status change API\n const result = await this.makeBulkStatusUpdate(\"seen\");\n\n this.broadcaster.emit(`items:all_seen`, { items });\n this.broadcastOverChannel(`items:all_seen`, { items });\n\n return result;\n }\n\n async markAsUnseen(itemOrItems: FeedItemOrItems) {\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"unseen\",\n { seen_at: null },\n \"unseen_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"unseen\");\n }\n\n async markAsRead(itemOrItems: FeedItemOrItems) {\n const now = new Date().toISOString();\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"read\",\n { read_at: now },\n \"unread_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"read\");\n }\n\n async markAllAsRead() {\n // To mark all of the messages as read we:\n // 1. Optimistically update *everything* we have in the store\n // 2. We decrement the `unread_count` to zero optimistically\n // 3. We issue the API call to the endpoint\n //\n // Note: there is the potential for a race condition here because the bulk\n // update is an async method, so if a new message comes in during this window before\n // the update has been processed we'll effectively reset the `unread_count` to be what it was.\n //\n // Note: here we optimistically handle the case whereby the feed is scoped to show only `unread`\n // items by removing everything from view.\n const { getState, setState } = this.store;\n const { metadata, items } = getState();\n\n const isViewingOnlyUnread = this.defaultOptions.status === \"unread\";\n\n // If we're looking at the unread view, then we want to remove all of the items optimistically\n // from the store given that nothing should be visible. We do this by resetting the store state\n // and setting the current metadata counts to 0\n if (isViewingOnlyUnread) {\n setState((store) =>\n store.resetStore({\n ...metadata,\n total_count: 0,\n unread_count: 0,\n }),\n );\n } else {\n // Otherwise we want to update the metadata and mark all of the items in the store as seen\n setState((store) => store.setMetadata({ ...metadata, unread_count: 0 }));\n\n const attrs = { read_at: new Date().toISOString() };\n const itemIds = items.map((item) => item.id);\n\n setState((store) => store.setItemAttrs(itemIds, attrs));\n }\n\n // Issue the API request to the bulk status change API\n const result = await this.makeBulkStatusUpdate(\"read\");\n\n this.broadcaster.emit(`items:all_read`, { items });\n this.broadcastOverChannel(`items:all_read`, { items });\n\n return result;\n }\n\n async markAsUnread(itemOrItems: FeedItemOrItems) {\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"unread\",\n { read_at: null },\n \"unread_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"unread\");\n }\n\n async markAsInteracted(itemOrItems: FeedItemOrItems) {\n const now = new Date().toISOString();\n this.optimisticallyPerformStatusUpdate(\n itemOrItems,\n \"interacted\",\n {\n read_at: now,\n interacted_at: now,\n },\n \"unread_count\",\n );\n\n return this.makeStatusUpdate(itemOrItems, \"interacted\");\n }\n\n /*\n Marking one or more items as archived should:\n\n - Decrement the badge count for any unread / unseen items\n - Remove the item from the feed list when the `archived` flag is \"exclude\" (default)\n\n TODO: how do we handle rollbacks?\n */\n async markAsArchived(itemOrItems: FeedItemOrItems) {\n const { getState, setState } = this.store;\n const state = getState();\n\n const shouldOptimisticallyRemoveItems =\n this.defaultOptions.archived === \"exclude\";\n\n const normalizedItems = Array.isArray(itemOrItems)\n ? itemOrItems\n : [itemOrItems];\n\n const itemIds: string[] = normalizedItems.map((item) => item.id);\n\n /*\n In the code here we want to optimistically update counts and items\n that are persisted such that we can display updates immediately on the feed\n without needing to make a network request.\n\n Note: right now this does *not* take into account offline handling or any extensive retry\n logic, so rollbacks aren't considered. That probably needs to be a future consideration for\n this library.\n\n Scenarios to consider:\n\n ## Feed scope to archived *only*\n\n - Counts should not be decremented\n - Items should not be removed\n\n ## Feed scoped to exclude archived items (the default)\n\n - Counts should be decremented\n - Items should be removed\n\n ## Feed scoped to include archived items as well\n\n - Counts should not be decremented\n - Items should not be removed\n */\n\n if (shouldOptimisticallyRemoveItems) {\n // If any of the items are unseen or unread, then capture as we'll want to decrement\n // the counts for these in the metadata we have\n const unseenCount = normalizedItems.filter((i) => !i.seen_at).length;\n const unreadCount = normalizedItems.filter((i) => !i.read_at).length;\n\n // Build the new metadata\n const updatedMetadata = {\n ...state.metadata,\n total_count: state.metadata.total_count - normalizedItems.length,\n unseen_count: state.metadata.unseen_count - unseenCount,\n unread_count: state.metadata.unread_count - unreadCount,\n };\n\n // Remove the archiving entries\n const entriesToSet = state.items.filter(\n (item) => !itemIds.includes(item.id),\n );\n\n setState((state) =>\n state.setResult({\n entries: entriesToSet,\n meta: updatedMetadata,\n page_info: state.pageInfo,\n }),\n );\n } else {\n // Mark all the entries being updated as archived either way so the state is correct\n state.setItemAttrs(itemIds, { archived_at: new Date().toISOString() });\n }\n\n return this.makeStatusUpdate(itemOrItems, \"archived\");\n }\n\n async markAllAsArchived() {\n // Note: there is the potential for a race condition here because the bulk\n // update is an async method, so if a new message comes in during this window before\n // the update has been processed we'll effectively reset the `unseen_count` to be what it was.\n const { setState, getState } = this.store;\n const { items } = getState();\n\n // Here if we're looking at a feed that excludes all of the archived items by default then we\n // will want to optimistically remove all of the items from the feed as they are now all excluded\n const shouldOptimisticallyRemoveItems =\n this.defaultOptions.archived === \"exclude\";\n\n if (shouldOptimisticallyRemoveItems) {\n // Reset the store to clear out all of items and reset the badge count\n setState((store) => store.resetStore());\n } else {\n // Mark all the entries being updated as archived either way so the state is correct\n setState((store) => {\n const itemIds = items.map((i) => i.id);\n store.setItemAttrs(itemIds, { archived_at: new Date().toISOString() });\n });\n }\n\n // Issue the API request to the bulk status change API\n const result = await this.makeBulkStatusUpdate(\"archive\");\n\n this.broadcaster.emit(`items:all_archived`, { items });\n this.broadcastOverChannel(`items:all_archived`, { items });\n\n return result;\n }\n\n async markAsUnarchived(itemOrItems: FeedItemOrItems) {\n this.optimisticallyPerformStatusUpdate(itemOrItems, \"unarchived\", {\n archived_at: null,\n });\n\n return this.makeStatusUpdate(itemOrItems, \"unarchived\");\n }\n\n /* Fetches the feed content, appending it to the store */\n async fetch(options: FetchFeedOptions = {}) {\n const { setState, getState } = this.store;\n const { networkStatus } = getState();\n\n // If there's an existing request in flight, then do nothing\n if (isRequestInFlight(networkStatus)) {\n return;\n }\n\n // Set the loading type based on the request type it is\n setState((store) =>\n store.setNetworkStatus(options.__loadingType ?? NetworkStatus.loading),\n );\n\n // Always include the default params, if they have been set\n const queryParams = {\n ...this.defaultOptions,\n ...options,\n // Unset options that should not be sent to the API\n __loadingType: undefined,\n __fetchSource: undefined,\n __experimentalCrossBrowserUpdates: undefined,\n };\n\n const result = await this.apiClient.makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.knock.userId}/feeds/${this.feedId}`,\n params: queryParams,\n });\n\n if (result.statusCode === \"error\" || !result.body) {\n setState((store) => store.setNetworkStatus(NetworkStatus.error));\n\n return {\n status: result.statusCode,\n data: result.error || result.body,\n };\n }\n\n const response = {\n entries: result.body.entries,\n meta: result.body.meta,\n page_info: result.body.page_info,\n };\n\n if (options.before) {\n const opts = { shouldSetPage: false, shouldAppend: true };\n setState((state) => state.setResult(response, opts));\n } else if (options.after) {\n const opts = { shouldSetPage: true, shouldAppend: true };\n setState((state) => state.setResult(response, opts));\n } else {\n setState((state) => state.setResult(response));\n }\n\n // Legacy `messages.new` event, should be removed in a future version\n this.broadcast(\"messages.new\", response);\n\n // Broadcast the appropriate event type depending on the fetch source\n const feedEventType: FeedEvent =\n options.__fetchSource === \"socket\"\n ? \"items.received.realtime\"\n : \"items.received.page\";\n\n const eventPayload = {\n items: response.entries as FeedItem[],\n metadata: response.meta as FeedMetadata,\n event: feedEventType,\n };\n\n this.broadcast(eventPayload.event, eventPayload);\n\n return { data: response, status: result.statusCode };\n }\n\n async fetchNextPage() {\n // Attempts to fetch the next page of results (if we have any)\n const { getState } = this.store;\n const { pageInfo } = getState();\n\n if (!pageInfo.after) {\n // Nothing more to fetch\n return;\n }\n\n this.fetch({\n after: pageInfo.after,\n __loadingType: NetworkStatus.fetchMore,\n });\n }\n\n private broadcast(\n eventName: FeedEvent,\n data: FeedResponse | FeedEventPayload,\n ) {\n this.broadcaster.emit(eventName, data);\n }\n\n // Invoked when a new real-time message comes in from the socket\n private async onNewMessageReceived({\n metadata,\n }: FeedMessagesReceivedPayload) {\n // Handle the new message coming in\n const { getState, setState } = this.store;\n const { items } = getState();\n const currentHead: FeedItem | undefined = items[0];\n // Optimistically set the badge counts\n setState((state) => state.setMetadata(metadata));\n // Fetch the items before the current head (if it exists)\n this.fetch({ before: currentHead?.__cursor, __fetchSource: \"socket\" });\n }\n\n private buildUserFeedId() {\n return `${this.feedId}:${this.knock.userId}`;\n }\n\n private optimisticallyPerformStatusUpdate(\n itemOrItems: FeedItemOrItems,\n type: Status,\n attrs: object,\n badgeCountAttr?: \"unread_count\" | \"unseen_count\",\n ) {\n const { getState, setState } = this.store;\n const normalizedItems = Array.isArray(itemOrItems)\n ? itemOrItems\n : [itemOrItems];\n const itemIds = normalizedItems.map((item) => item.id);\n\n if (badgeCountAttr) {\n const { metadata } = getState();\n\n // We only want to update the counts of items that have not already been counted towards the\n // badge count total to avoid updating the badge count unnecessarily.\n const itemsToUpdate = normalizedItems.filter((item) => {\n switch (type) {\n case \"seen\":\n return item.seen_at === null;\n case \"unseen\":\n return item.seen_at !== null;\n case \"read\":\n case \"interacted\":\n return item.read_at === null;\n case \"unread\":\n return item.read_at !== null;\n default:\n return true;\n }\n });\n\n // Tnis is a hack to determine the direction of whether we're\n // adding or removing from the badge count\n const direction = type.startsWith(\"un\")\n ? itemsToUpdate.length\n : -itemsToUpdate.length;\n\n setState((store) =>\n store.setMetadata({\n ...metadata,\n [badgeCountAttr]: Math.max(0, metadata[badgeCountAttr] + direction),\n }),\n );\n }\n\n // Update the items with the given attributes\n setState((store) => store.setItemAttrs(itemIds, attrs));\n }\n\n private async makeStatusUpdate(itemOrItems: FeedItemOrItems, type: Status) {\n // Always treat items as a batch to use the corresponding batch endpoint\n const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];\n const itemIds = items.map((item) => item.id);\n\n const result = await this.apiClient.makeRequest({\n method: \"POST\",\n url: `/v1/messages/batch/${type}`,\n data: { message_ids: itemIds },\n });\n\n // Emit the event that these items had their statuses changed\n // Note: we do this after the update to ensure that the server event actually completed\n this.broadcaster.emit(`items:${type}`, { items });\n this.broadcastOverChannel(`items:${type}`, { items });\n\n return result;\n }\n\n private async makeBulkStatusUpdate(type: \"seen\" | \"read\" | \"archive\") {\n // The base scope for the call should take into account all of the options currently\n // set on the feed, as well as being scoped for the current user. We do this so that\n // we ONLY make changes to the messages that are currently in view on this feed, and not\n // all messages that exist.\n const options = {\n user_ids: [this.knock.userId],\n engagement_status:\n this.defaultOptions.status !== \"all\"\n ? this.defaultOptions.status\n : undefined,\n archived: this.defaultOptions.archived,\n has_tenant: this.defaultOptions.has_tenant,\n tenants: this.defaultOptions.tenant\n ? [this.defaultOptions.tenant]\n : undefined,\n };\n\n return await this.apiClient.makeRequest({\n method: \"POST\",\n url: `/v1/channels/${this.feedId}/messages/bulk/${type}`,\n data: options,\n });\n }\n\n private broadcastOverChannel(type: string, payload: any) {\n // The broadcastChannel may not be available in non-browser environments\n if (!this.broadcastChannel) {\n return;\n }\n\n // Here we stringify our payload and try and send as JSON such that we\n // don't get any `An object could not be cloned` errors when trying to broadcast\n try {\n const stringifiedPayload = JSON.parse(JSON.stringify(payload));\n\n this.broadcastChannel.postMessage({\n type,\n payload: stringifiedPayload,\n });\n } catch (e) {\n console.warn(`Could not broadcast ${type}, got error: ${e}`);\n }\n }\n}\n\nexport default Feed;\n"],"mappings":";;;;AAEA,SAASA,aAAa,IAAIC,YAAY,QAAQ,eAAe;AAE7D,OAAOC,WAAW,MAAM,SAAS;AAmBjC,SAASC,iBAAiB,EAAE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/helpers/defineProperty";
|
|
2
2
|
import Feed from "./feed";
|
|
3
|
-
|
|
4
3
|
class FeedClient {
|
|
5
4
|
constructor(instance) {
|
|
6
5
|
_defineProperty(this, "instance", void 0);
|
|
7
|
-
|
|
8
6
|
this.instance = instance;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
initialize(feedChannelId) {
|
|
12
9
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
13
10
|
return new Feed(this.instance, feedChannelId, options);
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
}
|
|
17
|
-
|
|
18
13
|
export { Feed };
|
|
19
14
|
export default FeedClient;
|
|
20
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Feed","FeedClient","constructor","instance","_defineProperty","initialize","feedChannelId","options","arguments","length","undefined"],"sources":["../../../../src/clients/feed/index.ts"],"sourcesContent":["import Knock from \"../../knock\";\nimport Feed from \"./feed\";\nimport { FeedClientOptions } from \"./interfaces\";\n\nclass FeedClient {\n private instance: Knock;\n\n constructor(instance: Knock) {\n this.instance = instance;\n }\n\n initialize(feedChannelId: string, options: FeedClientOptions = {}) {\n return new Feed(this.instance, feedChannelId, options);\n }\n}\n\nexport { Feed };\nexport default FeedClient;\n"],"mappings":";AACA,OAAOA,IAAI,MAAM,QAAQ;AAGzB,MAAMC,UAAU,CAAC;EAGfC,WAAWA,CAACC,QAAe,EAAE;IAAAC,eAAA;IAC3B,IAAI,CAACD,QAAQ,GAAGA,QAAQ;EAC1B;EAEAE,UAAUA,CAACC,aAAqB,EAAmC;IAAA,IAAjCC,OAA0B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAC/D,OAAO,IAAIR,IAAI,CAAC,IAAI,CAACG,QAAQ,EAAEG,aAAa,EAAEC,OAAO,CAAC;EACxD;AACF;AAEA,SAASP,IAAI;AACb,eAAeC,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"interfaces.js","names":[],"sources":["../../../../src/clients/feed/interfaces.ts"],"sourcesContent":["import { Activity, GenericData, PageInfo, Recipient } from \"../../interfaces\";\nimport { NetworkStatus } from \"../../networkStatus\";\n\n// Specific feed interfaces\n\nexport interface FeedClientOptions {\n before?: string;\n after?: string;\n page_size?: number;\n status?: \"unread\" | \"read\" | \"unseen\" | \"seen\" | \"all\";\n // Optionally scope all notifications to a particular source only\n source?: string;\n // Optionally scope all requests to a particular tenant\n tenant?: string;\n // Optionally scope to notifications with any tenancy or no tenancy\n has_tenant?: boolean;\n // Optionally scope to notifications with any of the categories provided\n workflow_categories?: string[];\n // Optionally scope to a given archived status (defaults to `exclude`)\n archived?: \"include\" | \"exclude\" | \"only\";\n // Optionally scope all notifications that contain this argument as part of their trigger payload\n trigger_data?: GenericData;\n // Optionally enable cross browser feed updates for this feed\n __experimentalCrossBrowserUpdates?: boolean;\n}\n\nexport type FetchFeedOptions = {\n __loadingType?: NetworkStatus.loading | NetworkStatus.fetchMore;\n __fetchSource?: \"socket\" | \"http\";\n} & Omit<FeedClientOptions, \"__experimentalCrossBrowserUpdates\">;\n\nexport interface ContentBlock {\n content: string;\n rendered: string;\n type: \"markdown\" | \"text\";\n name: string;\n}\n\nexport interface NotificationSource {\n key: string;\n version_id: string;\n}\n\nexport interface FeedItem<T = GenericData> {\n __cursor: string;\n id: string;\n activities: Activity<T>[];\n actors: Recipient[];\n blocks: ContentBlock[];\n inserted_at: string;\n updated_at: string;\n read_at: string | null;\n seen_at: string | null;\n archived_at: string | null;\n total_activities: number;\n total_actors: number;\n data: T | null;\n source: NotificationSource;\n tenant: string | null;\n}\n\nexport interface FeedMetadata {\n total_count: number;\n unread_count: number;\n unseen_count: number;\n}\n\nexport interface FeedResponse {\n entries: FeedItem[];\n meta: FeedMetadata;\n page_info: PageInfo;\n}\n"],"mappings":""}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
4
|
import create from "zustand/vanilla";
|
|
8
5
|
import { NetworkStatus } from "../../networkStatus";
|
|
9
6
|
import { deduplicateItems, sortItems } from "./utils";
|
|
10
|
-
|
|
11
7
|
function processItems(items) {
|
|
12
8
|
var deduped = deduplicateItems(items);
|
|
13
9
|
var sorted = sortItems(deduped);
|
|
14
10
|
return sorted;
|
|
15
11
|
}
|
|
16
|
-
|
|
17
12
|
var defaultSetResultOptions = {
|
|
18
13
|
shouldSetPage: true,
|
|
19
14
|
shouldAppend: false
|
|
@@ -83,7 +78,6 @@ export default function createStore() {
|
|
|
83
78
|
if (itemUpdatesMap[item.id]) {
|
|
84
79
|
return _objectSpread(_objectSpread({}, item), itemUpdatesMap[item.id]);
|
|
85
80
|
}
|
|
86
|
-
|
|
87
81
|
return item;
|
|
88
82
|
});
|
|
89
83
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"store.js","names":["create","NetworkStatus","deduplicateItems","sortItems","processItems","items","deduped","sorted","defaultSetResultOptions","shouldSetPage","shouldAppend","initialStoreState","metadata","total_count","unread_count","unseen_count","pageInfo","before","after","page_size","createStore","set","_objectSpread","networkStatus","ready","loading","setLoading","setNetworkStatus","setResult","_ref","entries","meta","page_info","options","arguments","length","undefined","state","concat","setMetadata","resetStore","setItemAttrs","itemIds","attrs","itemUpdatesMap","reduce","acc","itemId","map","item","id"],"sources":["../../../../src/clients/feed/store.ts"],"sourcesContent":["import create from \"zustand/vanilla\";\nimport { NetworkStatus } from \"../../networkStatus\";\nimport { FeedItem } from \"./interfaces\";\nimport { FeedStoreState } from \"./types\";\nimport { deduplicateItems, sortItems } from \"./utils\";\n\nfunction processItems(items: FeedItem[]) {\n const deduped = deduplicateItems(items);\n const sorted = sortItems(deduped);\n\n return sorted;\n}\n\nconst defaultSetResultOptions = {\n shouldSetPage: true,\n shouldAppend: false,\n};\n\nconst initialStoreState = {\n items: [],\n metadata: {\n total_count: 0,\n unread_count: 0,\n unseen_count: 0,\n },\n pageInfo: {\n before: null,\n after: null,\n page_size: 50,\n },\n};\n\nexport default function createStore() {\n return create<FeedStoreState>((set) => ({\n // Keeps track of all of the items loaded\n ...initialStoreState,\n // The network status indicates what's happening with the request\n networkStatus: NetworkStatus.ready,\n loading: false,\n // TODO: remove this function from the store as we're now using the\n // `setNetworkStatus` function to derive this information instead\n setLoading: (loading) => set(() => ({ loading })),\n\n setNetworkStatus: (networkStatus: NetworkStatus) =>\n set(() => ({\n networkStatus,\n loading: networkStatus === NetworkStatus.loading,\n })),\n\n setResult: (\n { entries, meta, page_info },\n options = defaultSetResultOptions,\n ) =>\n set((state) => {\n // We resort the list on set, so concating everything is fine (if a bit suboptimal)\n const items = options.shouldAppend\n ? processItems(state.items.concat(entries))\n : entries;\n\n return {\n items,\n metadata: meta,\n pageInfo: options.shouldSetPage ? page_info : state.pageInfo,\n loading: false,\n networkStatus: NetworkStatus.ready,\n };\n }),\n\n setMetadata: (metadata) => set(() => ({ metadata })),\n\n resetStore: (metadata = initialStoreState.metadata) =>\n set(() => ({ ...initialStoreState, metadata })),\n\n setItemAttrs: (itemIds, attrs) => {\n // Create a map for the items to the updates to be made\n const itemUpdatesMap: { [id: string]: object } = itemIds.reduce(\n (acc, itemId) => ({ ...acc, [itemId]: attrs }),\n {},\n );\n\n return set((state) => {\n const items = state.items.map((item) => {\n if (itemUpdatesMap[item.id]) {\n return { ...item, ...itemUpdatesMap[item.id] };\n }\n\n return item;\n });\n\n return { items };\n });\n },\n }));\n}\n"],"mappings":";;;AAAA,OAAOA,MAAM,MAAM,iBAAiB;AACpC,SAASC,aAAa,QAAQ,qBAAqB;AAGnD,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,SAAS;AAErD,SAASC,YAAYA,CAACC,KAAiB,EAAE;EACvC,IAAMC,OAAO,GAAGJ,gBAAgB,CAACG,KAAK,CAAC;EACvC,IAAME,MAAM,GAAGJ,SAAS,CAACG,OAAO,CAAC;EAEjC,OAAOC,MAAM;AACf;AAEA,IAAMC,uBAAuB,GAAG;EAC9BC,aAAa,EAAE,IAAI;EACnBC,YAAY,EAAE;AAChB,CAAC;AAED,IAAMC,iBAAiB,GAAG;EACxBN,KAAK,EAAE,EAAE;EACTO,QAAQ,EAAE;IACRC,WAAW,EAAE,CAAC;IACdC,YAAY,EAAE,CAAC;IACfC,YAAY,EAAE;EAChB,CAAC;EACDC,QAAQ,EAAE;IACRC,MAAM,EAAE,IAAI;IACZC,KAAK,EAAE,IAAI;IACXC,SAAS,EAAE;EACb;AACF,CAAC;AAED,eAAe,SAASC,WAAWA,CAAA,EAAG;EAC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AAiB,CAACC,QAAQ;MAAA,OAChDS,GAAG,CAAC,MAAAC,aAAA,CAAAA,aAAA,KAAYX,iBAAiB;QAAEC;MAAQ,EAAG,CAAC;IAAA;IAEjD6B,YAAY,EAAEA,CAACC,OAAO,EAAEC,KAAK,KAAK;MAChC;MACA,IAAMC,cAAwC,GAAGF,OAAO,CAACG,MAAM,CAC7D,CAACC,GAAG,EAAEC,MAAM,KAAAzB,aAAA,CAAAA,aAAA,KAAWwB,GAAG;QAAE,CAACC,MAAM,GAAGJ;MAAK,EAAG,EAC9C,CAAC,CACH,CAAC;MAED,OAAOtB,GAAG,CAAEgB,KAAK,IAAK;QACpB,IAAMhC,KAAK,GAAGgC,KAAK,CAAChC,KAAK,CAAC2C,GAAG,CAAEC,IAAI,IAAK;UACtC,IAAIL,cAAc,CAACK,IAAI,CAACC,EAAE,CAAC,EAAE;YAC3B,OAAA5B,aAAA,CAAAA,aAAA,KAAY2B,IAAI,GAAKL,cAAc,CAACK,IAAI,CAACC,EAAE,CAAC;UAC9C;UAEA,OAAOD,IAAI;QACb,CAAC,CAAC;QAEF,OAAO;UAAE5C;QAAM,CAAC;MAClB,CAAC,CAAC;IACJ;EAAC,EACD,CAAC;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/clients/feed/types.ts"],"sourcesContent":["import { PageInfo } from \"../../interfaces\";\nimport { NetworkStatus } from \"../../networkStatus\";\nimport { FeedItem, FeedMetadata, FeedResponse } from \"./interfaces\";\n\nexport type StoreFeedResultOptions = {\n shouldSetPage?: boolean;\n shouldAppend?: boolean;\n};\n\nexport type FeedStoreState = {\n items: FeedItem[];\n pageInfo: PageInfo;\n metadata: FeedMetadata;\n loading: boolean;\n networkStatus: NetworkStatus;\n setResult: (response: FeedResponse, opts?: StoreFeedResultOptions) => void;\n setMetadata: (metadata: FeedMetadata) => void;\n setLoading: (loading: boolean) => void;\n setNetworkStatus: (networkStatus: NetworkStatus) => void;\n setItemAttrs: (itemIds: string[], attrs: object) => void;\n resetStore: (metadata?: FeedMetadata) => void;\n};\n\nexport type FeedMessagesReceivedPayload = {\n metadata: FeedMetadata;\n};\n\n/*\nEvent types:\n- `messages.new`: legacy event fired for all messages (feed items) received, real-time or not\n- `items.received.realtime`: all real-time items received via a socket update\n- `items.received.page`: invoked every time a page is fetched (like on initial load)\n*/\nexport type FeedRealTimeEvent = \"messages.new\";\n\nexport type FeedEvent =\n | FeedRealTimeEvent\n | \"items.received.page\"\n | \"items.received.realtime\"\n | \"items.archived\"\n | \"items.unarchived\"\n | \"items.seen\"\n | \"items.unseen\"\n | \"items.read\"\n | \"items.unread\"\n | \"items.all_archived\"\n | \"items.all_read\"\n | \"items.all_seen\";\n\n// Because we can bind to wild card feed events, this is here to accomodate whatever can be bound to\nexport type BindableFeedEvent = FeedEvent | \"items.received.*\" | \"items.*\";\n\nexport type FeedEventPayload = {\n event: Omit<FeedEvent, \"messages.new\">;\n items: FeedItem[];\n metadata: FeedMetadata;\n};\n\nexport type FeedRealTimeCallback = (resp: FeedResponse) => void;\n\nexport type FeedEventCallback = (payload: FeedEventPayload) => void;\n\nexport type FeedItemOrItems = FeedItem | FeedItem[];\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["deduplicateItems","items","seen","values","reduce","acc","item","id","sortItems","sort","a","b","Date","inserted_at","getTime"],"sources":["../../../../src/clients/feed/utils.ts"],"sourcesContent":["import { FeedItem } from \"./interfaces\";\n\nexport function deduplicateItems(items: FeedItem[]): FeedItem[] {\n const seen: Record<string, boolean> = {};\n const values: FeedItem[] = [];\n\n return items.reduce((acc, item) => {\n if (seen[item.id]) {\n return acc;\n }\n\n seen[item.id] = true;\n return [...acc, item];\n }, values);\n}\n\nexport function sortItems(items: FeedItem[]) {\n return items.sort((a, b) => {\n return (\n new Date(b.inserted_at).getTime() - new Date(a.inserted_at).getTime()\n );\n });\n}\n"],"mappings":"AAEA,OAAO,SAASA,gBAAgBA,CAACC,KAAiB,EAAc;EAC9D,IAAMC,IAA6B,GAAG,CAAC,CAAC;EACxC,IAAMC,MAAkB,GAAG,EAAE;EAE7B,OAAOF,KAAK,CAACG,MAAM,CAAC,CAACC,GAAG,EAAEC,IAAI,KAAK;IACjC,IAAIJ,IAAI,CAACI,IAAI,CAACC,EAAE,CAAC,EAAE;MACjB,OAAOF,GAAG;IACZ;IAEAH,IAAI,CAACI,IAAI,CAACC,EAAE,CAAC,GAAG,IAAI;IACpB,OAAO,CAAC,GAAGF,GAAG,EAAEC,IAAI,CAAC;EACvB,CAAC,EAAEH,MAAM,CAAC;AACZ;AAEA,OAAO,SAASK,SAASA,CAACP,KAAiB,EAAE;EAC3C,OAAOA,KAAK,CAACQ,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAK;IAC1B,OACE,IAAIC,IAAI,CAACD,CAAC,CAACE,WAAW,CAAC,CAACC,OAAO,CAAC,CAAC,GAAG,IAAIF,IAAI,CAACF,CAAC,CAACG,WAAW,CAAC,CAACC,OAAO,CAAC,CAAC;EAEzE,CAAC,CAAC;AACJ"}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
var DEFAULT_PREFERENCE_SET_ID = "default";
|
|
4
|
-
|
|
5
4
|
function buildUpdateParam(param) {
|
|
6
5
|
if (typeof param === "object") {
|
|
7
6
|
return param;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
return {
|
|
11
9
|
subscribed: param
|
|
12
10
|
};
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
class Preferences {
|
|
16
13
|
constructor(instance) {
|
|
17
14
|
_defineProperty(this, "instance", void 0);
|
|
18
|
-
|
|
19
15
|
this.instance = instance;
|
|
20
16
|
}
|
|
21
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `user.getAllPreferences()` instead
|
|
20
|
+
*/
|
|
22
21
|
getAll() {
|
|
23
22
|
var _this = this;
|
|
24
|
-
|
|
25
23
|
return _asyncToGenerator(function* () {
|
|
26
24
|
var result = yield _this.instance.client().makeRequest({
|
|
27
25
|
method: "GET",
|
|
@@ -31,10 +29,12 @@ class Preferences {
|
|
|
31
29
|
})();
|
|
32
30
|
}
|
|
33
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use `user.getPreferences()` instead
|
|
34
|
+
*/
|
|
34
35
|
get() {
|
|
35
36
|
var _arguments = arguments,
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
_this2 = this;
|
|
38
38
|
return _asyncToGenerator(function* () {
|
|
39
39
|
var options = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {};
|
|
40
40
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -46,10 +46,12 @@ class Preferences {
|
|
|
46
46
|
})();
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
51
|
+
*/
|
|
49
52
|
set(preferenceSet) {
|
|
50
53
|
var _arguments2 = arguments,
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
_this3 = this;
|
|
53
55
|
return _asyncToGenerator(function* () {
|
|
54
56
|
var options = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : {};
|
|
55
57
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -62,10 +64,12 @@ class Preferences {
|
|
|
62
64
|
})();
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
69
|
+
*/
|
|
65
70
|
setChannelTypes(channelTypePreferences) {
|
|
66
71
|
var _arguments3 = arguments,
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
_this4 = this;
|
|
69
73
|
return _asyncToGenerator(function* () {
|
|
70
74
|
var options = _arguments3.length > 1 && _arguments3[1] !== undefined ? _arguments3[1] : {};
|
|
71
75
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -78,10 +82,12 @@ class Preferences {
|
|
|
78
82
|
})();
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
87
|
+
*/
|
|
81
88
|
setChannelType(channelType, setting) {
|
|
82
89
|
var _arguments4 = arguments,
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
_this5 = this;
|
|
85
91
|
return _asyncToGenerator(function* () {
|
|
86
92
|
var options = _arguments4.length > 2 && _arguments4[2] !== undefined ? _arguments4[2] : {};
|
|
87
93
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -96,10 +102,12 @@ class Preferences {
|
|
|
96
102
|
})();
|
|
97
103
|
}
|
|
98
104
|
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
107
|
+
*/
|
|
99
108
|
setWorkflows(workflowPreferences) {
|
|
100
109
|
var _arguments5 = arguments,
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
_this6 = this;
|
|
103
111
|
return _asyncToGenerator(function* () {
|
|
104
112
|
var options = _arguments5.length > 1 && _arguments5[1] !== undefined ? _arguments5[1] : {};
|
|
105
113
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -112,10 +120,12 @@ class Preferences {
|
|
|
112
120
|
})();
|
|
113
121
|
}
|
|
114
122
|
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
125
|
+
*/
|
|
115
126
|
setWorkflow(workflowKey, setting) {
|
|
116
127
|
var _arguments6 = arguments,
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
_this7 = this;
|
|
119
129
|
return _asyncToGenerator(function* () {
|
|
120
130
|
var options = _arguments6.length > 2 && _arguments6[2] !== undefined ? _arguments6[2] : {};
|
|
121
131
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -129,10 +139,12 @@ class Preferences {
|
|
|
129
139
|
})();
|
|
130
140
|
}
|
|
131
141
|
|
|
142
|
+
/**
|
|
143
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
144
|
+
*/
|
|
132
145
|
setCategories(categoryPreferences) {
|
|
133
146
|
var _arguments7 = arguments,
|
|
134
|
-
|
|
135
|
-
|
|
147
|
+
_this8 = this;
|
|
136
148
|
return _asyncToGenerator(function* () {
|
|
137
149
|
var options = _arguments7.length > 1 && _arguments7[1] !== undefined ? _arguments7[1] : {};
|
|
138
150
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -145,10 +157,12 @@ class Preferences {
|
|
|
145
157
|
})();
|
|
146
158
|
}
|
|
147
159
|
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated Use `user.setPreferences(preferenceSet, options)` instead
|
|
162
|
+
*/
|
|
148
163
|
setCategory(categoryKey, setting) {
|
|
149
164
|
var _arguments8 = arguments,
|
|
150
|
-
|
|
151
|
-
|
|
165
|
+
_this9 = this;
|
|
152
166
|
return _asyncToGenerator(function* () {
|
|
153
167
|
var options = _arguments8.length > 2 && _arguments8[2] !== undefined ? _arguments8[2] : {};
|
|
154
168
|
var preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
|
|
@@ -161,16 +175,12 @@ class Preferences {
|
|
|
161
175
|
return _this9.handleResponse(result);
|
|
162
176
|
})();
|
|
163
177
|
}
|
|
164
|
-
|
|
165
178
|
handleResponse(response) {
|
|
166
179
|
if (response.statusCode === "error") {
|
|
167
180
|
throw new Error(response.error || response.body);
|
|
168
181
|
}
|
|
169
|
-
|
|
170
182
|
return response.body;
|
|
171
183
|
}
|
|
172
|
-
|
|
173
184
|
}
|
|
174
|
-
|
|
175
185
|
export default Preferences;
|
|
176
186
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/clients/preferences/index.ts"],"names":["DEFAULT_PREFERENCE_SET_ID","buildUpdateParam","param","subscribed","Preferences","constructor","instance","getAll","result","client","makeRequest","method","url","userId","handleResponse","get","options","preferenceSetId","preferenceSet","set","data","setChannelTypes","channelTypePreferences","setChannelType","channelType","setting","setWorkflows","workflowPreferences","setWorkflow","workflowKey","params","setCategories","categoryPreferences","setCategory","categoryKey","response","statusCode","Error","error","body"],"mappings":";;AAYA,IAAMA,yBAAyB,GAAG,SAAlC;;AAEA,SAASC,gBAAT,CAA0BC,KAA1B,EAA4D;AAC1D,MAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AAC7B,WAAOA,KAAP;AACD;;AAED,SAAO;AAAEC,IAAAA,UAAU,EAAED;AAAd,GAAP;AACD;;AAED,MAAME,WAAN,CAAkB;AAGhBC,EAAAA,WAAW,CAACC,QAAD,EAAkB;AAAA;;AAC3B,SAAKA,QAAL,GAAgBA,QAAhB;AACD;;AAEKC,EAAAA,MAAM,GAAG;AAAA;;AAAA;AACb,UAAMC,MAAM,SAAS,KAAI,CAACF,QAAL,CAAcG,MAAd,GAAuBC,WAAvB,CAAmC;AACtDC,QAAAA,MAAM,EAAE,KAD8C;AAEtDC,QAAAA,GAAG,sBAAe,KAAI,CAACN,QAAL,CAAcO,MAA7B;AAFmD,OAAnC,CAArB;AAKA,aAAO,KAAI,CAACC,cAAL,CAAoBN,MAApB,CAAP;AANa;AAOd;;AAEKO,EAAAA,GAAG,GAAkC;AAAA;AAAA;;AAAA;AAAA,UAAjCC,OAAiC,0EAAJ,EAAI;AACzC,UAAMC,eAAe,GAAGD,OAAO,CAACE,aAAR,IAAyBlB,yBAAjD;A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AEU;AAHgD,OAAnC,CAArB;AAMA,aAAO,MAAI,CAAChB,cAAL,CAAoBN,MAApB,CAAP;AAVA;AAWD;;AAEOM,EAAAA,cAAc,CAACqB,QAAD,EAAwB;AAC5C,QAAIA,QAAQ,CAACC,UAAT,KAAwB,OAA5B,EAAqC;AACnC,YAAM,IAAIC,KAAJ,CAAUF,QAAQ,CAACG,KAAT,IAAkBH,QAAQ,CAACI,IAArC,CAAN;AACD;;AAED,WAAOJ,QAAQ,CAACI,IAAhB;AACD;;AA/Ie;;AAkJlB,eAAenC,WAAf","sourcesContent":["import { ApiResponse } from \"../../api\";\nimport Knock from \"../../knock\";\nimport {\n ChannelTypePreferences,\n ChannelType,\n PreferenceOptions,\n SetPreferencesProperties,\n WorkflowPreferenceSetting,\n WorkflowPreferences,\n PreferenceSet,\n} from \"./interfaces\";\n\nconst DEFAULT_PREFERENCE_SET_ID = \"default\";\n\nfunction buildUpdateParam(param: WorkflowPreferenceSetting) {\n if (typeof param === \"object\") {\n return param;\n }\n\n return { subscribed: param };\n}\n\nclass Preferences {\n private instance: Knock;\n\n constructor(instance: Knock) {\n this.instance = instance;\n }\n\n async getAll() {\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences`,\n });\n\n return this.handleResponse(result);\n }\n\n async get(options: PreferenceOptions = {}) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n });\n\n return this.handleResponse(result);\n }\n\n async set(\n preferenceSet: SetPreferencesProperties,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n data: preferenceSet,\n });\n\n return this.handleResponse(result);\n }\n\n async setChannelTypes(\n channelTypePreferences: ChannelTypePreferences,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/channel_types`,\n data: channelTypePreferences,\n });\n\n return this.handleResponse(result);\n }\n\n async setChannelType(\n channelType: ChannelType,\n setting: boolean,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/channel_types/${channelType}`,\n data: { subscribed: setting },\n });\n\n return this.handleResponse(result);\n }\n\n async setWorkflows(\n workflowPreferences: WorkflowPreferences,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/workflows`,\n data: workflowPreferences,\n });\n\n return this.handleResponse(result);\n }\n\n async setWorkflow(\n workflowKey: string,\n setting: WorkflowPreferenceSetting,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n const params = buildUpdateParam(setting);\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`,\n data: params,\n });\n\n return this.handleResponse(result);\n }\n\n async setCategories(\n categoryPreferences: WorkflowPreferences,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/categories`,\n data: categoryPreferences,\n });\n\n return this.handleResponse(result);\n }\n\n async setCategory(\n categoryKey: string,\n setting: WorkflowPreferenceSetting,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n const params = buildUpdateParam(setting);\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/categories/${categoryKey}`,\n data: params,\n });\n\n return this.handleResponse(result);\n }\n\n private handleResponse(response: ApiResponse) {\n if (response.statusCode === \"error\") {\n throw new Error(response.error || response.body);\n }\n\n return response.body as PreferenceSet;\n }\n}\n\nexport default Preferences;\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["DEFAULT_PREFERENCE_SET_ID","buildUpdateParam","param","subscribed","Preferences","constructor","instance","_defineProperty","getAll","_this","_asyncToGenerator","result","client","makeRequest","method","url","concat","userId","handleResponse","get","_arguments","arguments","_this2","options","length","undefined","preferenceSetId","preferenceSet","set","_arguments2","_this3","data","setChannelTypes","channelTypePreferences","_arguments3","_this4","setChannelType","channelType","setting","_arguments4","_this5","setWorkflows","workflowPreferences","_arguments5","_this6","setWorkflow","workflowKey","_arguments6","_this7","params","setCategories","categoryPreferences","_arguments7","_this8","setCategory","categoryKey","_arguments8","_this9","response","statusCode","Error","error","body"],"sources":["../../../../src/clients/preferences/index.ts"],"sourcesContent":["import { ApiResponse } from \"../../api\";\nimport Knock from \"../../knock\";\nimport {\n ChannelTypePreferences,\n ChannelType,\n PreferenceOptions,\n SetPreferencesProperties,\n WorkflowPreferenceSetting,\n WorkflowPreferences,\n PreferenceSet,\n} from \"./interfaces\";\n\nconst DEFAULT_PREFERENCE_SET_ID = \"default\";\n\nfunction buildUpdateParam(param: WorkflowPreferenceSetting) {\n if (typeof param === \"object\") {\n return param;\n }\n\n return { subscribed: param };\n}\n\nclass Preferences {\n private instance: Knock;\n\n constructor(instance: Knock) {\n this.instance = instance;\n }\n\n /**\n * @deprecated Use `user.getAllPreferences()` instead\n */\n async getAll() {\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences`,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.getPreferences()` instead\n */\n async get(options: PreferenceOptions = {}) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async set(\n preferenceSet: SetPreferencesProperties,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n data: preferenceSet,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async setChannelTypes(\n channelTypePreferences: ChannelTypePreferences,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/channel_types`,\n data: channelTypePreferences,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async setChannelType(\n channelType: ChannelType,\n setting: boolean,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/channel_types/${channelType}`,\n data: { subscribed: setting },\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async setWorkflows(\n workflowPreferences: WorkflowPreferences,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/workflows`,\n data: workflowPreferences,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async setWorkflow(\n workflowKey: string,\n setting: WorkflowPreferenceSetting,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n const params = buildUpdateParam(setting);\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`,\n data: params,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async setCategories(\n categoryPreferences: WorkflowPreferences,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/categories`,\n data: categoryPreferences,\n });\n\n return this.handleResponse(result);\n }\n\n /**\n * @deprecated Use `user.setPreferences(preferenceSet, options)` instead\n */\n async setCategory(\n categoryKey: string,\n setting: WorkflowPreferenceSetting,\n options: PreferenceOptions = {},\n ) {\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n const params = buildUpdateParam(setting);\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}/categories/${categoryKey}`,\n data: params,\n });\n\n return this.handleResponse(result);\n }\n\n private handleResponse(response: ApiResponse) {\n if (response.statusCode === \"error\") {\n throw new Error(response.error || response.body);\n }\n\n return response.body as PreferenceSet;\n }\n}\n\nexport default Preferences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ACW,MAAM,mBAAAD,MAAA,CAAgBU,eAAe,gBAAa;QAClFK,IAAI,EAAEoB;MACR,CAAC,CAAC;MAEF,OAAOE,MAAI,CAACnC,cAAc,CAACP,MAAM,CAAC;IAAC;EACrC;;EAEA;AACF;AACA;EACQ2C,WAAWA,CACfC,WAAmB,EACnBjB,OAAkC,EAElC;IAAA,IAAAkB,WAAA,GAAAnC,SAAA;MAAAoC,MAAA;IAAA,OAAA/C,iBAAA;MAAA,IADAa,OAA0B,GAAAiC,WAAA,CAAAhC,MAAA,QAAAgC,WAAA,QAAA/B,SAAA,GAAA+B,WAAA,MAAG,CAAC,CAAC;MAE/B,IAAM9B,eAAe,GAAGH,OAAO,CAACI,aAAa,IAAI3B,yBAAyB;MAC1E,IAAMiD,MAAM,GAAGhD,gBAAgB,CAACqC,OAAO,CAAC;MAExC,IAAM3B,MAAM,SAAS8C,MAAI,CAACnD,QAAQ,CAACM,MAAM,CAAC,CAAC,CAACC,WAAW,CAAC;QACtDC,MAAM,EAAE,KAAK;QACbC,GAAG,eAAAC,MAAA,CAAeyC,MAAI,CAACnD,QAAQ,CAACW,MAAM,mBAAAD,MAAA,CAAgBU,eAAe,kBAAAV,MAAA,CAAeuC,WAAW,CAAE;QACjGxB,IAAI,EAAEkB;MACR,CAAC,CAAC;MAEF,OAAOQ,MAAI,CAACvC,cAAc,CAACP,MAAM,CAAC;IAAC;EACrC;EAEQO,cAAcA,CAACwC,QAAqB,EAAE;IAC5C,IAAIA,QAAQ,CAACC,UAAU,KAAK,OAAO,EAAE;MACnC,MAAM,IAAIC,KAAK,CAACF,QAAQ,CAACG,KAAK,IAAIH,QAAQ,CAACI,IAAI,CAAC;IAClD;IAEA,OAAOJ,QAAQ,CAACI,IAAI;EACtB;AACF;AAEA,eAAe1D,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"interfaces.js","names":[],"sources":["../../../../src/clients/preferences/interfaces.ts"],"sourcesContent":["// Channel types supported in Knock\n// TODO: it would be great to pull this in from an external location\nexport type ChannelType =\n | \"email\"\n | \"in_app_feed\"\n | \"sms\"\n | \"push\"\n | \"chat\"\n | \"http\";\n\nexport type ChannelTypePreferences = {\n [K in ChannelType]?: boolean;\n};\n\nexport type WorkflowPreferenceSetting =\n | boolean\n | { channel_types: ChannelTypePreferences };\n\nexport type WorkflowPreferences = Partial<\n Record<string, WorkflowPreferenceSetting>\n>;\n\nexport interface SetPreferencesProperties {\n workflows: WorkflowPreferences;\n categories: WorkflowPreferences;\n channel_types: ChannelTypePreferences;\n}\n\nexport interface PreferenceSet {\n id: string;\n categories: WorkflowPreferences;\n workflows: WorkflowPreferences;\n channel_types: ChannelTypePreferences;\n}\n\nexport interface PreferenceOptions {\n preferenceSet?: string;\n}\n\nexport interface GetPreferencesOptions extends PreferenceOptions {\n tenant?: string;\n}\n"],"mappings":""}
|