@baukit/notifications-expo 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Koss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # `@baukit/notifications-expo`
2
+
3
+ The `expo-notifications` implementation of the `@baukit/notifications-core` platform port. It
4
+ schedules, lists, and cancels only the notifications that carry its owner's marker, and it never
5
+ calls `cancelAllScheduledNotificationsAsync`.
6
+
7
+ ```ts
8
+ import { resolveNotificationOccurrences } from '@baukit/notifications-core';
9
+ import {
10
+ createExpoOwnedNotificationScheduler,
11
+ IOS_PENDING_NOTIFICATION_LIMIT,
12
+ } from '@baukit/notifications-expo';
13
+ import * as Notifications from 'expo-notifications';
14
+
15
+ const scheduler = createExpoOwnedNotificationScheduler(Notifications, {
16
+ pendingLimit: IOS_PENDING_NOTIFICATION_LIMIT,
17
+ });
18
+
19
+ const { desired } = resolveNotificationOccurrences({ occurrences, timeZone, gap, fold, clock, horizonDays });
20
+ const outcome = await scheduler.replaceOwned(
21
+ { namespace: 'reminders' },
22
+ desired.map((entry) => ({
23
+ ...entry,
24
+ content: { content: { title: entry.title, body: entry.body }, channelId: 'reminders' },
25
+ })),
26
+ );
27
+ ```
28
+
29
+ - Create one scheduler per app and share it. Replacements for one namespace run one at a time on
30
+ that instance.
31
+ - Each request gets the identifier `baukit:<namespace>:<logicalId>` and a DATE trigger at the
32
+ planned instant. `channelId` is optional and Android only.
33
+ - The adapter writes its marker under the `baukitNotification` key in `content.data`, next to the
34
+ product's own data. Product data that already uses that key rejects with
35
+ `NotificationPlanError('reserved_data_key')`.
36
+ - Permission counts as granted when `granted` is true or the iOS status is authorized, provisional,
37
+ or ephemeral. `undetermined` counts as not granted, so the product asks first.
38
+ - `IOS_PENDING_NOTIFICATION_LIMIT` is 64. The limit counts every pending request on the device, so
39
+ pass a lower number when other features schedule too.
40
+ - The outcome reports list, cancel, permission, schedule, and limit failures by code and logical ID,
41
+ never with the notification content.
42
+
43
+ The module is passed in, and the package imports only types from `expo-notifications`, so the
44
+ package itself loads in Node and in tests. The tests run the core conformance suite against a
45
+ mocked module.
46
+
47
+ ## Boundaries
48
+
49
+ The package does not request permission, create Android channels, set a notification handler, or
50
+ choose copy. It does not support repeating triggers; plan a rolling horizon and replace it when the
51
+ app opens or the plan changes.
@@ -0,0 +1,13 @@
1
+ import { type NotificationPlatform, type OwnedNotificationScheduler, type OwnedNotificationSchedulerOptions } from '@baukit/notifications-core';
2
+ import type * as ExpoNotifications from 'expo-notifications';
3
+ import type { NotificationContentInput } from 'expo-notifications';
4
+ export declare const IOS_PENDING_NOTIFICATION_LIMIT = 64;
5
+ export type ExpoNotificationsApi = Pick<typeof ExpoNotifications, 'getAllScheduledNotificationsAsync' | 'cancelScheduledNotificationAsync' | 'scheduleNotificationAsync' | 'getPermissionsAsync' | 'SchedulableTriggerInputTypes' | 'IosAuthorizationStatus'>;
6
+ export interface ExpoNotificationContent {
7
+ readonly content: NotificationContentInput;
8
+ readonly channelId?: string;
9
+ }
10
+ export type ExpoOwnedNotificationSchedulerOptions = OwnedNotificationSchedulerOptions;
11
+ export declare function createExpoNotificationPlatform(api: ExpoNotificationsApi): NotificationPlatform<ExpoNotificationContent>;
12
+ export declare function createExpoOwnedNotificationScheduler(api: ExpoNotificationsApi, options?: ExpoOwnedNotificationSchedulerOptions): OwnedNotificationScheduler<ExpoNotificationContent>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAE/B,KAAK,iCAAiC,EAEvC,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,KAAK,iBAAiB,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAEV,wBAAwB,EAGzB,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAEjD,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,OAAO,iBAAiB,EACtB,mCAAmC,GACnC,kCAAkC,GAClC,2BAA2B,GAC3B,qBAAqB,GACrB,8BAA8B,GAC9B,wBAAwB,CAC3B,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,qCAAqC,GAAG,iCAAiC,CAAC;AAItF,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,oBAAoB,GACxB,oBAAoB,CAAC,uBAAuB,CAAC,CAoB/C;AAED,wBAAgB,oCAAoC,CAClD,GAAG,EAAE,oBAAoB,EACzB,OAAO,GAAE,qCAA0C,GAClD,0BAA0B,CAAC,uBAAuB,CAAC,CAWrD"}
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ import { createOwnedNotificationScheduler, decodeOwnedNotificationMarker, encodeOwnedNotificationMarker, NotificationPlanError, OWNED_NOTIFICATION_DATA_KEY, } from '@baukit/notifications-core';
2
+ export const IOS_PENDING_NOTIFICATION_LIMIT = 64;
3
+ const UNDETERMINED = 'undetermined';
4
+ export function createExpoNotificationPlatform(api) {
5
+ return {
6
+ async list() {
7
+ const requests = await api.getAllScheduledNotificationsAsync();
8
+ return requests.map(pendingNotification);
9
+ },
10
+ cancel(identifier) {
11
+ return api.cancelScheduledNotificationAsync(identifier);
12
+ },
13
+ async permission() {
14
+ return permissionFrom(api, await api.getPermissionsAsync());
15
+ },
16
+ async schedule(request) {
17
+ await api.scheduleNotificationAsync({
18
+ identifier: request.identifier,
19
+ content: contentWithMarker(request),
20
+ trigger: dateTrigger(api, request),
21
+ });
22
+ },
23
+ };
24
+ }
25
+ export function createExpoOwnedNotificationScheduler(api, options = {}) {
26
+ const scheduler = createOwnedNotificationScheduler(createExpoNotificationPlatform(api), options);
27
+ return {
28
+ replaceOwned(owner, desired, replaceOptions) {
29
+ const reserved = desired.find((entry) => hasReservedKey(entry.content.content));
30
+ if (reserved !== undefined) {
31
+ return Promise.reject(new NotificationPlanError('reserved_data_key', reserved.logicalId));
32
+ }
33
+ return scheduler.replaceOwned(owner, desired, replaceOptions);
34
+ },
35
+ };
36
+ }
37
+ function pendingNotification(request) {
38
+ return {
39
+ identifier: request.identifier,
40
+ marker: decodeOwnedNotificationMarker(request.content.data?.[OWNED_NOTIFICATION_DATA_KEY]),
41
+ };
42
+ }
43
+ function hasReservedKey(content) {
44
+ return content.data !== undefined && Object.hasOwn(content.data, OWNED_NOTIFICATION_DATA_KEY);
45
+ }
46
+ function contentWithMarker(request) {
47
+ const { content } = request.content;
48
+ return {
49
+ ...content,
50
+ data: {
51
+ ...content.data,
52
+ [OWNED_NOTIFICATION_DATA_KEY]: encodeOwnedNotificationMarker(request.marker),
53
+ },
54
+ };
55
+ }
56
+ function dateTrigger(api, request) {
57
+ const trigger = {
58
+ type: api.SchedulableTriggerInputTypes.DATE,
59
+ date: request.marker.epochMilliseconds,
60
+ };
61
+ const { channelId } = request.content;
62
+ return channelId === undefined ? trigger : { ...trigger, channelId };
63
+ }
64
+ function permissionFrom(api, permission) {
65
+ const iosStatus = permission.ios?.status;
66
+ if (permission.granted ||
67
+ iosStatus === api.IosAuthorizationStatus.AUTHORIZED ||
68
+ iosStatus === api.IosAuthorizationStatus.PROVISIONAL ||
69
+ iosStatus === api.IosAuthorizationStatus.EPHEMERAL) {
70
+ return 'granted';
71
+ }
72
+ const status = permission.status;
73
+ return status === UNDETERMINED ? 'undetermined' : 'denied';
74
+ }
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,6BAA6B,EAC7B,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,GAO5B,MAAM,4BAA4B,CAAC;AASpC,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAmBjD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,UAAU,8BAA8B,CAC5C,GAAyB;IAEzB,OAAO;QACL,KAAK,CAAC,IAAI;YACR,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,iCAAiC,EAAE,CAAC;YAC/D,OAAO,QAAQ,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,CAAC,UAAU;YACf,OAAO,GAAG,CAAC,gCAAgC,CAAC,UAAU,CAAC,CAAC;QAC1D,CAAC;QACD,KAAK,CAAC,UAAU;YACd,OAAO,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC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"description": "Optional expo-notifications adapter for @baukit/notifications-core that replaces only notifications carrying one owner's namespace marker.",
5
+ "license": "MIT",
6
+ "author": "Patrick Koss",
7
+ "homepage": "https://github.com/PatrickKoss/baukit#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/PatrickKoss/baukit.git",
11
+ "directory": "typescript/packages/notifications-expo"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/PatrickKoss/baukit/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=24.0.0"
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.json",
38
+ "prepare": "pnpm run build",
39
+ "test": "tsc -p tsconfig.test.json && vitest run --config ../../vitest.config.ts && node ../../scripts/test-packed-exports.mjs",
40
+ "lint": "eslint src --max-warnings=0",
41
+ "format:check": "prettier --check src package.json tsconfig.json tsconfig.test.json"
42
+ },
43
+ "devDependencies": {
44
+ "@baukit/localization-core": "workspace:*",
45
+ "@baukit/notifications-core": "workspace:*",
46
+ "expo-notifications": "57.0.13",
47
+ "typescript": "6.0.3",
48
+ "vitest": "4.1.10"
49
+ },
50
+ "peerDependencies": {
51
+ "@baukit/notifications-core": "^0.5.0",
52
+ "expo-notifications": "^57.0.13"
53
+ }
54
+ }