@chipmobilesdk/rn-notification 0.5.0 → 0.7.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/CHANGELOG.md +184 -0
- package/README.md +108 -16
- package/lib/commonjs/advanced.js +139 -0
- package/lib/commonjs/advanced.js.map +1 -0
- package/lib/commonjs/channel/migrate.js +246 -0
- package/lib/commonjs/channel/migrate.js.map +1 -0
- package/lib/commonjs/channel/tone-map.js +120 -0
- package/lib/commonjs/channel/tone-map.js.map +1 -0
- package/lib/commonjs/channel/validate-tone.js +61 -0
- package/lib/commonjs/channel/validate-tone.js.map +1 -0
- package/lib/commonjs/contract/channel.js +52 -0
- package/lib/commonjs/contract/channel.js.map +1 -0
- package/lib/commonjs/contract/diagnostics.js +25 -0
- package/lib/commonjs/contract/diagnostics.js.map +1 -0
- package/lib/commonjs/contract/errors.js +126 -0
- package/lib/commonjs/contract/errors.js.map +1 -0
- package/lib/commonjs/contract/hash.js +35 -0
- package/lib/commonjs/contract/hash.js.map +1 -0
- package/lib/commonjs/contract/index.js +94 -0
- package/lib/commonjs/contract/index.js.map +1 -0
- package/lib/commonjs/contract/interaction.js +37 -0
- package/lib/commonjs/contract/interaction.js.map +1 -0
- package/lib/commonjs/contract/notification.js +42 -0
- package/lib/commonjs/contract/notification.js.map +1 -0
- package/lib/commonjs/contract/permission.js +2 -0
- package/lib/commonjs/contract/permission.js.map +1 -0
- package/lib/commonjs/contract/reconcile.js +6 -0
- package/lib/commonjs/contract/reconcile.js.map +1 -0
- package/lib/commonjs/contract/recurrence.js +53 -0
- package/lib/commonjs/contract/recurrence.js.map +1 -0
- package/lib/commonjs/diagnostics/burst.js +89 -0
- package/lib/commonjs/diagnostics/burst.js.map +1 -0
- package/lib/commonjs/diagnostics/events.js +63 -0
- package/lib/commonjs/diagnostics/events.js.map +1 -0
- package/lib/commonjs/diagnostics/redact.js +48 -0
- package/lib/commonjs/diagnostics/redact.js.map +1 -0
- package/lib/commonjs/diagnostics/snapshot.js +68 -0
- package/lib/commonjs/diagnostics/snapshot.js.map +1 -0
- package/lib/commonjs/engine/adapter.js +6 -0
- package/lib/commonjs/engine/adapter.js.map +1 -0
- package/lib/commonjs/engine/codec.js +84 -0
- package/lib/commonjs/engine/codec.js.map +1 -0
- package/lib/commonjs/engine/notify-kit/events.js +148 -0
- package/lib/commonjs/engine/notify-kit/events.js.map +1 -0
- package/lib/commonjs/engine/notify-kit/module.js +119 -0
- package/lib/commonjs/engine/notify-kit/module.js.map +1 -0
- package/lib/commonjs/engine/notify-kit/platform/android.js +159 -0
- package/lib/commonjs/engine/notify-kit/platform/android.js.map +1 -0
- package/lib/commonjs/engine/notify-kit/platform/index.js +57 -0
- package/lib/commonjs/engine/notify-kit/platform/index.js.map +1 -0
- package/lib/commonjs/engine/notify-kit/platform/ios.js +54 -0
- package/lib/commonjs/engine/notify-kit/platform/ios.js.map +1 -0
- package/lib/commonjs/engine/notify-kit/platform/types.js +6 -0
- package/lib/commonjs/engine/notify-kit/platform/types.js.map +1 -0
- package/lib/commonjs/engine/notify-kit-engine.js +260 -0
- package/lib/commonjs/engine/notify-kit-engine.js.map +1 -0
- package/lib/commonjs/index.js +367 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/initialize.js +187 -0
- package/lib/commonjs/initialize.js.map +1 -0
- package/lib/commonjs/interaction/index.js +120 -0
- package/lib/commonjs/interaction/index.js.map +1 -0
- package/lib/commonjs/maintenance/cycle.js +108 -0
- package/lib/commonjs/maintenance/cycle.js.map +1 -0
- package/lib/commonjs/maintenance/permission-refresh.js +39 -0
- package/lib/commonjs/maintenance/permission-refresh.js.map +1 -0
- package/lib/commonjs/maintenance/reanchor.js +99 -0
- package/lib/commonjs/maintenance/reanchor.js.map +1 -0
- package/lib/commonjs/maintenance/toggle.js +50 -0
- package/lib/commonjs/maintenance/toggle.js.map +1 -0
- package/lib/commonjs/maintenance/verify.js +70 -0
- package/lib/commonjs/maintenance/verify.js.map +1 -0
- package/lib/commonjs/maintenance/window-refresh.js +53 -0
- package/lib/commonjs/maintenance/window-refresh.js.map +1 -0
- package/lib/commonjs/notifications.js +161 -0
- package/lib/commonjs/notifications.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/permission/index.js +182 -0
- package/lib/commonjs/permission/index.js.map +1 -0
- package/lib/commonjs/permission/state.js +92 -0
- package/lib/commonjs/permission/state.js.map +1 -0
- package/lib/commonjs/push/envelope.js +141 -0
- package/lib/commonjs/push/envelope.js.map +1 -0
- package/lib/commonjs/push/fcm-provider.js +122 -0
- package/lib/commonjs/push/fcm-provider.js.map +1 -0
- package/lib/commonjs/push/gate.js +162 -0
- package/lib/commonjs/push/gate.js.map +1 -0
- package/lib/commonjs/push/index.js +47 -0
- package/lib/commonjs/push/index.js.map +1 -0
- package/lib/commonjs/push/instructions.js +101 -0
- package/lib/commonjs/push/instructions.js.map +1 -0
- package/lib/commonjs/push/provider-adapter.js +6 -0
- package/lib/commonjs/push/provider-adapter.js.map +1 -0
- package/lib/commonjs/push/signout.js +55 -0
- package/lib/commonjs/push/signout.js.map +1 -0
- package/lib/commonjs/reconcile/chunk.js +49 -0
- package/lib/commonjs/reconcile/chunk.js.map +1 -0
- package/lib/commonjs/reconcile/diff.js +105 -0
- package/lib/commonjs/reconcile/diff.js.map +1 -0
- package/lib/commonjs/reconcile/duplicates.js +60 -0
- package/lib/commonjs/reconcile/duplicates.js.map +1 -0
- package/lib/commonjs/reconcile/index.js +164 -0
- package/lib/commonjs/reconcile/index.js.map +1 -0
- package/lib/commonjs/reconcile/truncate.js +50 -0
- package/lib/commonjs/reconcile/truncate.js.map +1 -0
- package/lib/commonjs/recurrence/clock-guard.js +65 -0
- package/lib/commonjs/recurrence/clock-guard.js.map +1 -0
- package/lib/commonjs/recurrence/expand.js +254 -0
- package/lib/commonjs/recurrence/expand.js.map +1 -0
- package/lib/commonjs/recurrence/index.js +212 -0
- package/lib/commonjs/recurrence/index.js.map +1 -0
- package/lib/commonjs/repeat/expiry.js +41 -0
- package/lib/commonjs/repeat/expiry.js.map +1 -0
- package/lib/commonjs/repeat/index.js +100 -0
- package/lib/commonjs/repeat/index.js.map +1 -0
- package/lib/commonjs/repeat/marker.js +58 -0
- package/lib/commonjs/repeat/marker.js.map +1 -0
- package/lib/commonjs/repeat/place.js +83 -0
- package/lib/commonjs/repeat/place.js.map +1 -0
- package/lib/commonjs/schedule/anchor.js +243 -0
- package/lib/commonjs/schedule/anchor.js.map +1 -0
- package/lib/commonjs/schedule/index.js +142 -0
- package/lib/commonjs/schedule/index.js.map +1 -0
- package/lib/commonjs/schedule/partition.js +59 -0
- package/lib/commonjs/schedule/partition.js.map +1 -0
- package/lib/commonjs/schedule/resolve-moment.js +72 -0
- package/lib/commonjs/schedule/resolve-moment.js.map +1 -0
- package/lib/commonjs/schedule/validate-content.js +101 -0
- package/lib/commonjs/schedule/validate-content.js.map +1 -0
- package/lib/commonjs/schedule/validate-identifier.js +126 -0
- package/lib/commonjs/schedule/validate-identifier.js.map +1 -0
- package/lib/commonjs/schedule/writer.js +44 -0
- package/lib/commonjs/schedule/writer.js.map +1 -0
- package/lib/commonjs/state/caps.js +101 -0
- package/lib/commonjs/state/caps.js.map +1 -0
- package/lib/commonjs/state/dedup-ledger.js +39 -0
- package/lib/commonjs/state/dedup-ledger.js.map +1 -0
- package/lib/commonjs/state/interaction-buffer.js +98 -0
- package/lib/commonjs/state/interaction-buffer.js.map +1 -0
- package/lib/commonjs/state/mmkv-store.js +75 -0
- package/lib/commonjs/state/mmkv-store.js.map +1 -0
- package/lib/commonjs/state/permission-history.js +64 -0
- package/lib/commonjs/state/permission-history.js.map +1 -0
- package/lib/commonjs/state/record.js +269 -0
- package/lib/commonjs/state/record.js.map +1 -0
- package/lib/commonjs/state/reset.js +37 -0
- package/lib/commonjs/state/reset.js.map +1 -0
- package/lib/commonjs/state/series-ledger.js +71 -0
- package/lib/commonjs/state/series-ledger.js.map +1 -0
- package/lib/commonjs/state/store.js +39 -0
- package/lib/commonjs/state/store.js.map +1 -0
- package/lib/commonjs/testing/conformance/index.js +218 -0
- package/lib/commonjs/testing/conformance/index.js.map +1 -0
- package/lib/commonjs/testing/fake-engine.js +338 -0
- package/lib/commonjs/testing/fake-engine.js.map +1 -0
- package/lib/commonjs/testing/fake-provider.js +93 -0
- package/lib/commonjs/testing/fake-provider.js.map +1 -0
- package/lib/commonjs/testing/faults.js +59 -0
- package/lib/commonjs/testing/faults.js.map +1 -0
- package/lib/commonjs/testing/index.js +54 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/testing/measure.js +298 -0
- package/lib/commonjs/testing/measure.js.map +1 -0
- package/lib/module/advanced.js +29 -0
- package/lib/module/advanced.js.map +1 -0
- package/lib/module/channel/migrate.js +242 -0
- package/lib/module/channel/migrate.js.map +1 -0
- package/lib/module/channel/tone-map.js +112 -0
- package/lib/module/channel/tone-map.js.map +1 -0
- package/lib/module/channel/validate-tone.js +57 -0
- package/lib/module/channel/validate-tone.js.map +1 -0
- package/lib/module/contract/channel.js +48 -0
- package/lib/module/contract/channel.js.map +1 -0
- package/lib/module/contract/diagnostics.js +21 -0
- package/lib/module/contract/diagnostics.js.map +1 -0
- package/lib/module/contract/errors.js +119 -0
- package/lib/module/contract/errors.js.map +1 -0
- package/lib/module/contract/hash.js +29 -0
- package/lib/module/contract/hash.js.map +1 -0
- package/lib/module/contract/index.js +13 -0
- package/lib/module/contract/index.js.map +1 -0
- package/lib/module/contract/interaction.js +33 -0
- package/lib/module/contract/interaction.js.map +1 -0
- package/lib/module/contract/notification.js +38 -0
- package/lib/module/contract/notification.js.map +1 -0
- package/lib/module/contract/permission.js +2 -0
- package/lib/module/contract/permission.js.map +1 -0
- package/lib/module/contract/reconcile.js +4 -0
- package/lib/module/contract/reconcile.js.map +1 -0
- package/lib/module/contract/recurrence.js +49 -0
- package/lib/module/contract/recurrence.js.map +1 -0
- package/lib/module/diagnostics/burst.js +85 -0
- package/lib/module/diagnostics/burst.js.map +1 -0
- package/lib/module/diagnostics/events.js +58 -0
- package/lib/module/diagnostics/events.js.map +1 -0
- package/lib/module/diagnostics/redact.js +44 -0
- package/lib/module/diagnostics/redact.js.map +1 -0
- package/lib/module/diagnostics/snapshot.js +64 -0
- package/lib/module/diagnostics/snapshot.js.map +1 -0
- package/lib/module/engine/adapter.js +4 -0
- package/lib/module/engine/adapter.js.map +1 -0
- package/lib/module/engine/codec.js +79 -0
- package/lib/module/engine/codec.js.map +1 -0
- package/lib/module/engine/notify-kit/events.js +139 -0
- package/lib/module/engine/notify-kit/events.js.map +1 -0
- package/lib/module/engine/notify-kit/module.js +113 -0
- package/lib/module/engine/notify-kit/module.js.map +1 -0
- package/lib/module/engine/notify-kit/platform/android.js +155 -0
- package/lib/module/engine/notify-kit/platform/android.js.map +1 -0
- package/lib/module/engine/notify-kit/platform/index.js +51 -0
- package/lib/module/engine/notify-kit/platform/index.js.map +1 -0
- package/lib/module/engine/notify-kit/platform/ios.js +49 -0
- package/lib/module/engine/notify-kit/platform/ios.js.map +1 -0
- package/lib/module/engine/notify-kit/platform/types.js +4 -0
- package/lib/module/engine/notify-kit/platform/types.js.map +1 -0
- package/lib/module/engine/notify-kit-engine.js +257 -0
- package/lib/module/engine/notify-kit-engine.js.map +1 -0
- package/lib/module/index.js +98 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initialize.js +182 -0
- package/lib/module/initialize.js.map +1 -0
- package/lib/module/interaction/index.js +116 -0
- package/lib/module/interaction/index.js.map +1 -0
- package/lib/module/maintenance/cycle.js +102 -0
- package/lib/module/maintenance/cycle.js.map +1 -0
- package/lib/module/maintenance/permission-refresh.js +34 -0
- package/lib/module/maintenance/permission-refresh.js.map +1 -0
- package/lib/module/maintenance/reanchor.js +94 -0
- package/lib/module/maintenance/reanchor.js.map +1 -0
- package/lib/module/maintenance/toggle.js +45 -0
- package/lib/module/maintenance/toggle.js.map +1 -0
- package/lib/module/maintenance/verify.js +65 -0
- package/lib/module/maintenance/verify.js.map +1 -0
- package/lib/module/maintenance/window-refresh.js +48 -0
- package/lib/module/maintenance/window-refresh.js.map +1 -0
- package/lib/module/notifications.js +157 -0
- package/lib/module/notifications.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/permission/index.js +178 -0
- package/lib/module/permission/index.js.map +1 -0
- package/lib/module/permission/state.js +83 -0
- package/lib/module/permission/state.js.map +1 -0
- package/lib/module/push/envelope.js +137 -0
- package/lib/module/push/envelope.js.map +1 -0
- package/lib/module/push/fcm-provider.js +119 -0
- package/lib/module/push/fcm-provider.js.map +1 -0
- package/lib/module/push/gate.js +158 -0
- package/lib/module/push/gate.js.map +1 -0
- package/lib/module/push/index.js +16 -0
- package/lib/module/push/index.js.map +1 -0
- package/lib/module/push/instructions.js +97 -0
- package/lib/module/push/instructions.js.map +1 -0
- package/lib/module/push/provider-adapter.js +4 -0
- package/lib/module/push/provider-adapter.js.map +1 -0
- package/lib/module/push/signout.js +51 -0
- package/lib/module/push/signout.js.map +1 -0
- package/lib/module/reconcile/chunk.js +43 -0
- package/lib/module/reconcile/chunk.js.map +1 -0
- package/lib/module/reconcile/diff.js +101 -0
- package/lib/module/reconcile/diff.js.map +1 -0
- package/lib/module/reconcile/duplicates.js +56 -0
- package/lib/module/reconcile/duplicates.js.map +1 -0
- package/lib/module/reconcile/index.js +161 -0
- package/lib/module/reconcile/index.js.map +1 -0
- package/lib/module/reconcile/truncate.js +46 -0
- package/lib/module/reconcile/truncate.js.map +1 -0
- package/lib/module/recurrence/clock-guard.js +60 -0
- package/lib/module/recurrence/clock-guard.js.map +1 -0
- package/lib/module/recurrence/expand.js +248 -0
- package/lib/module/recurrence/expand.js.map +1 -0
- package/lib/module/recurrence/index.js +208 -0
- package/lib/module/recurrence/index.js.map +1 -0
- package/lib/module/repeat/expiry.js +37 -0
- package/lib/module/repeat/expiry.js.map +1 -0
- package/lib/module/repeat/index.js +67 -0
- package/lib/module/repeat/index.js.map +1 -0
- package/lib/module/repeat/marker.js +51 -0
- package/lib/module/repeat/marker.js.map +1 -0
- package/lib/module/repeat/place.js +79 -0
- package/lib/module/repeat/place.js.map +1 -0
- package/lib/module/schedule/anchor.js +234 -0
- package/lib/module/schedule/anchor.js.map +1 -0
- package/lib/module/schedule/index.js +137 -0
- package/lib/module/schedule/index.js.map +1 -0
- package/lib/module/schedule/partition.js +53 -0
- package/lib/module/schedule/partition.js.map +1 -0
- package/lib/module/schedule/resolve-moment.js +66 -0
- package/lib/module/schedule/resolve-moment.js.map +1 -0
- package/lib/module/schedule/validate-content.js +95 -0
- package/lib/module/schedule/validate-content.js.map +1 -0
- package/lib/module/schedule/validate-identifier.js +119 -0
- package/lib/module/schedule/validate-identifier.js.map +1 -0
- package/lib/module/schedule/writer.js +40 -0
- package/lib/module/schedule/writer.js.map +1 -0
- package/lib/module/state/caps.js +96 -0
- package/lib/module/state/caps.js.map +1 -0
- package/lib/module/state/dedup-ledger.js +34 -0
- package/lib/module/state/dedup-ledger.js.map +1 -0
- package/lib/module/state/interaction-buffer.js +92 -0
- package/lib/module/state/interaction-buffer.js.map +1 -0
- package/lib/module/state/mmkv-store.js +71 -0
- package/lib/module/state/mmkv-store.js.map +1 -0
- package/lib/module/state/permission-history.js +56 -0
- package/lib/module/state/permission-history.js.map +1 -0
- package/lib/module/state/record.js +264 -0
- package/lib/module/state/record.js.map +1 -0
- package/lib/module/state/reset.js +32 -0
- package/lib/module/state/reset.js.map +1 -0
- package/lib/module/state/series-ledger.js +62 -0
- package/lib/module/state/series-ledger.js.map +1 -0
- package/lib/module/state/store.js +35 -0
- package/lib/module/state/store.js.map +1 -0
- package/lib/module/testing/conformance/index.js +214 -0
- package/lib/module/testing/conformance/index.js.map +1 -0
- package/lib/module/testing/fake-engine.js +335 -0
- package/lib/module/testing/fake-engine.js.map +1 -0
- package/lib/module/testing/fake-provider.js +89 -0
- package/lib/module/testing/fake-provider.js.map +1 -0
- package/lib/module/testing/faults.js +55 -0
- package/lib/module/testing/faults.js.map +1 -0
- package/lib/module/testing/index.js +19 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/module/testing/measure.js +294 -0
- package/lib/module/testing/measure.js.map +1 -0
- package/lib/typescript/commonjs/advanced.d.ts +36 -0
- package/lib/typescript/commonjs/advanced.d.ts.map +1 -0
- package/lib/typescript/commonjs/channel/migrate.d.ts +38 -0
- package/lib/typescript/commonjs/channel/migrate.d.ts.map +1 -0
- package/lib/typescript/commonjs/channel/tone-map.d.ts +34 -0
- package/lib/typescript/commonjs/channel/tone-map.d.ts.map +1 -0
- package/lib/typescript/commonjs/channel/validate-tone.d.ts +23 -0
- package/lib/typescript/commonjs/channel/validate-tone.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/channel.d.ts +185 -0
- package/lib/typescript/commonjs/contract/channel.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/diagnostics.d.ts +92 -0
- package/lib/typescript/commonjs/contract/diagnostics.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/errors.d.ts +91 -0
- package/lib/typescript/commonjs/contract/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/hash.d.ts +14 -0
- package/lib/typescript/commonjs/contract/hash.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/index.d.ts +10 -0
- package/lib/typescript/commonjs/contract/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/interaction.d.ts +53 -0
- package/lib/typescript/commonjs/contract/interaction.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/notification.d.ts +110 -0
- package/lib/typescript/commonjs/contract/notification.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/permission.d.ts +49 -0
- package/lib/typescript/commonjs/contract/permission.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/reconcile.d.ts +82 -0
- package/lib/typescript/commonjs/contract/reconcile.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/recurrence.d.ts +118 -0
- package/lib/typescript/commonjs/contract/recurrence.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/burst.d.ts +39 -0
- package/lib/typescript/commonjs/diagnostics/burst.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts +28 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/redact.d.ts +22 -0
- package/lib/typescript/commonjs/diagnostics/redact.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/snapshot.d.ts +40 -0
- package/lib/typescript/commonjs/diagnostics/snapshot.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/adapter.d.ts +172 -0
- package/lib/typescript/commonjs/engine/adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/codec.d.ts +20 -0
- package/lib/typescript/commonjs/engine/codec.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit/events.d.ts +37 -0
- package/lib/typescript/commonjs/engine/notify-kit/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit/module.d.ts +103 -0
- package/lib/typescript/commonjs/engine/notify-kit/module.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/android.d.ts +3 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/android.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/index.d.ts +12 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/ios.d.ts +3 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/ios.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/types.d.ts +33 -0
- package/lib/typescript/commonjs/engine/notify-kit/platform/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/notify-kit-engine.d.ts +25 -0
- package/lib/typescript/commonjs/engine/notify-kit-engine.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +106 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/initialize.d.ts +74 -0
- package/lib/typescript/commonjs/initialize.d.ts.map +1 -0
- package/lib/typescript/commonjs/interaction/index.d.ts +53 -0
- package/lib/typescript/commonjs/interaction/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/maintenance/cycle.d.ts +77 -0
- package/lib/typescript/commonjs/maintenance/cycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/maintenance/permission-refresh.d.ts +19 -0
- package/lib/typescript/commonjs/maintenance/permission-refresh.d.ts.map +1 -0
- package/lib/typescript/commonjs/maintenance/reanchor.d.ts +26 -0
- package/lib/typescript/commonjs/maintenance/reanchor.d.ts.map +1 -0
- package/lib/typescript/commonjs/maintenance/toggle.d.ts +35 -0
- package/lib/typescript/commonjs/maintenance/toggle.d.ts.map +1 -0
- package/lib/typescript/commonjs/maintenance/verify.d.ts +32 -0
- package/lib/typescript/commonjs/maintenance/verify.d.ts.map +1 -0
- package/lib/typescript/commonjs/maintenance/window-refresh.d.ts +29 -0
- package/lib/typescript/commonjs/maintenance/window-refresh.d.ts.map +1 -0
- package/lib/typescript/commonjs/notifications.d.ts +78 -0
- package/lib/typescript/commonjs/notifications.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/permission/index.d.ts +57 -0
- package/lib/typescript/commonjs/permission/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/permission/state.d.ts +41 -0
- package/lib/typescript/commonjs/permission/state.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/envelope.d.ts +33 -0
- package/lib/typescript/commonjs/push/envelope.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/fcm-provider.d.ts +43 -0
- package/lib/typescript/commonjs/push/fcm-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/gate.d.ts +57 -0
- package/lib/typescript/commonjs/push/gate.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/index.d.ts +19 -0
- package/lib/typescript/commonjs/push/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/instructions.d.ts +45 -0
- package/lib/typescript/commonjs/push/instructions.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/provider-adapter.d.ts +50 -0
- package/lib/typescript/commonjs/push/provider-adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/push/signout.d.ts +33 -0
- package/lib/typescript/commonjs/push/signout.d.ts.map +1 -0
- package/lib/typescript/commonjs/reconcile/chunk.d.ts +24 -0
- package/lib/typescript/commonjs/reconcile/chunk.d.ts.map +1 -0
- package/lib/typescript/commonjs/reconcile/diff.d.ts +54 -0
- package/lib/typescript/commonjs/reconcile/diff.d.ts.map +1 -0
- package/lib/typescript/commonjs/reconcile/duplicates.d.ts +32 -0
- package/lib/typescript/commonjs/reconcile/duplicates.d.ts.map +1 -0
- package/lib/typescript/commonjs/reconcile/index.d.ts +35 -0
- package/lib/typescript/commonjs/reconcile/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/reconcile/truncate.d.ts +26 -0
- package/lib/typescript/commonjs/reconcile/truncate.d.ts.map +1 -0
- package/lib/typescript/commonjs/recurrence/clock-guard.d.ts +37 -0
- package/lib/typescript/commonjs/recurrence/clock-guard.d.ts.map +1 -0
- package/lib/typescript/commonjs/recurrence/expand.d.ts +75 -0
- package/lib/typescript/commonjs/recurrence/expand.d.ts.map +1 -0
- package/lib/typescript/commonjs/recurrence/index.d.ts +40 -0
- package/lib/typescript/commonjs/recurrence/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/repeat/expiry.d.ts +23 -0
- package/lib/typescript/commonjs/repeat/expiry.d.ts.map +1 -0
- package/lib/typescript/commonjs/repeat/index.d.ts +49 -0
- package/lib/typescript/commonjs/repeat/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/repeat/marker.d.ts +36 -0
- package/lib/typescript/commonjs/repeat/marker.d.ts.map +1 -0
- package/lib/typescript/commonjs/repeat/place.d.ts +39 -0
- package/lib/typescript/commonjs/repeat/place.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/anchor.d.ts +118 -0
- package/lib/typescript/commonjs/schedule/anchor.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/index.d.ts +40 -0
- package/lib/typescript/commonjs/schedule/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/partition.d.ts +29 -0
- package/lib/typescript/commonjs/schedule/partition.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/resolve-moment.d.ts +35 -0
- package/lib/typescript/commonjs/schedule/resolve-moment.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/validate-content.d.ts +42 -0
- package/lib/typescript/commonjs/schedule/validate-content.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/validate-identifier.d.ts +30 -0
- package/lib/typescript/commonjs/schedule/validate-identifier.d.ts.map +1 -0
- package/lib/typescript/commonjs/schedule/writer.d.ts +36 -0
- package/lib/typescript/commonjs/schedule/writer.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/caps.d.ts +51 -0
- package/lib/typescript/commonjs/state/caps.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/dedup-ledger.d.ts +21 -0
- package/lib/typescript/commonjs/state/dedup-ledger.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/interaction-buffer.d.ts +30 -0
- package/lib/typescript/commonjs/state/interaction-buffer.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/mmkv-store.d.ts +33 -0
- package/lib/typescript/commonjs/state/mmkv-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/permission-history.d.ts +20 -0
- package/lib/typescript/commonjs/state/permission-history.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/record.d.ts +134 -0
- package/lib/typescript/commonjs/state/record.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/reset.d.ts +22 -0
- package/lib/typescript/commonjs/state/reset.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/series-ledger.d.ts +47 -0
- package/lib/typescript/commonjs/state/series-ledger.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/store.d.ts +20 -0
- package/lib/typescript/commonjs/state/store.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/index.d.ts +32 -0
- package/lib/typescript/commonjs/testing/conformance/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/fake-engine.d.ts +91 -0
- package/lib/typescript/commonjs/testing/fake-engine.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/fake-provider.d.ts +35 -0
- package/lib/typescript/commonjs/testing/fake-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/faults.d.ts +38 -0
- package/lib/typescript/commonjs/testing/faults.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +22 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/measure.d.ts +59 -0
- package/lib/typescript/commonjs/testing/measure.d.ts.map +1 -0
- package/lib/typescript/module/advanced.d.ts +36 -0
- package/lib/typescript/module/advanced.d.ts.map +1 -0
- package/lib/typescript/module/channel/migrate.d.ts +38 -0
- package/lib/typescript/module/channel/migrate.d.ts.map +1 -0
- package/lib/typescript/module/channel/tone-map.d.ts +34 -0
- package/lib/typescript/module/channel/tone-map.d.ts.map +1 -0
- package/lib/typescript/module/channel/validate-tone.d.ts +23 -0
- package/lib/typescript/module/channel/validate-tone.d.ts.map +1 -0
- package/lib/typescript/module/contract/channel.d.ts +185 -0
- package/lib/typescript/module/contract/channel.d.ts.map +1 -0
- package/lib/typescript/module/contract/diagnostics.d.ts +92 -0
- package/lib/typescript/module/contract/diagnostics.d.ts.map +1 -0
- package/lib/typescript/module/contract/errors.d.ts +91 -0
- package/lib/typescript/module/contract/errors.d.ts.map +1 -0
- package/lib/typescript/module/contract/hash.d.ts +14 -0
- package/lib/typescript/module/contract/hash.d.ts.map +1 -0
- package/lib/typescript/module/contract/index.d.ts +10 -0
- package/lib/typescript/module/contract/index.d.ts.map +1 -0
- package/lib/typescript/module/contract/interaction.d.ts +53 -0
- package/lib/typescript/module/contract/interaction.d.ts.map +1 -0
- package/lib/typescript/module/contract/notification.d.ts +110 -0
- package/lib/typescript/module/contract/notification.d.ts.map +1 -0
- package/lib/typescript/module/contract/permission.d.ts +49 -0
- package/lib/typescript/module/contract/permission.d.ts.map +1 -0
- package/lib/typescript/module/contract/reconcile.d.ts +82 -0
- package/lib/typescript/module/contract/reconcile.d.ts.map +1 -0
- package/lib/typescript/module/contract/recurrence.d.ts +118 -0
- package/lib/typescript/module/contract/recurrence.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/burst.d.ts +39 -0
- package/lib/typescript/module/diagnostics/burst.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/events.d.ts +28 -0
- package/lib/typescript/module/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/redact.d.ts +22 -0
- package/lib/typescript/module/diagnostics/redact.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/snapshot.d.ts +40 -0
- package/lib/typescript/module/diagnostics/snapshot.d.ts.map +1 -0
- package/lib/typescript/module/engine/adapter.d.ts +172 -0
- package/lib/typescript/module/engine/adapter.d.ts.map +1 -0
- package/lib/typescript/module/engine/codec.d.ts +20 -0
- package/lib/typescript/module/engine/codec.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit/events.d.ts +37 -0
- package/lib/typescript/module/engine/notify-kit/events.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit/module.d.ts +103 -0
- package/lib/typescript/module/engine/notify-kit/module.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit/platform/android.d.ts +3 -0
- package/lib/typescript/module/engine/notify-kit/platform/android.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit/platform/index.d.ts +12 -0
- package/lib/typescript/module/engine/notify-kit/platform/index.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit/platform/ios.d.ts +3 -0
- package/lib/typescript/module/engine/notify-kit/platform/ios.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit/platform/types.d.ts +33 -0
- package/lib/typescript/module/engine/notify-kit/platform/types.d.ts.map +1 -0
- package/lib/typescript/module/engine/notify-kit-engine.d.ts +25 -0
- package/lib/typescript/module/engine/notify-kit-engine.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +106 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/initialize.d.ts +74 -0
- package/lib/typescript/module/initialize.d.ts.map +1 -0
- package/lib/typescript/module/interaction/index.d.ts +53 -0
- package/lib/typescript/module/interaction/index.d.ts.map +1 -0
- package/lib/typescript/module/maintenance/cycle.d.ts +77 -0
- package/lib/typescript/module/maintenance/cycle.d.ts.map +1 -0
- package/lib/typescript/module/maintenance/permission-refresh.d.ts +19 -0
- package/lib/typescript/module/maintenance/permission-refresh.d.ts.map +1 -0
- package/lib/typescript/module/maintenance/reanchor.d.ts +26 -0
- package/lib/typescript/module/maintenance/reanchor.d.ts.map +1 -0
- package/lib/typescript/module/maintenance/toggle.d.ts +35 -0
- package/lib/typescript/module/maintenance/toggle.d.ts.map +1 -0
- package/lib/typescript/module/maintenance/verify.d.ts +32 -0
- package/lib/typescript/module/maintenance/verify.d.ts.map +1 -0
- package/lib/typescript/module/maintenance/window-refresh.d.ts +29 -0
- package/lib/typescript/module/maintenance/window-refresh.d.ts.map +1 -0
- package/lib/typescript/module/notifications.d.ts +78 -0
- package/lib/typescript/module/notifications.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/permission/index.d.ts +57 -0
- package/lib/typescript/module/permission/index.d.ts.map +1 -0
- package/lib/typescript/module/permission/state.d.ts +41 -0
- package/lib/typescript/module/permission/state.d.ts.map +1 -0
- package/lib/typescript/module/push/envelope.d.ts +33 -0
- package/lib/typescript/module/push/envelope.d.ts.map +1 -0
- package/lib/typescript/module/push/fcm-provider.d.ts +43 -0
- package/lib/typescript/module/push/fcm-provider.d.ts.map +1 -0
- package/lib/typescript/module/push/gate.d.ts +57 -0
- package/lib/typescript/module/push/gate.d.ts.map +1 -0
- package/lib/typescript/module/push/index.d.ts +19 -0
- package/lib/typescript/module/push/index.d.ts.map +1 -0
- package/lib/typescript/module/push/instructions.d.ts +45 -0
- package/lib/typescript/module/push/instructions.d.ts.map +1 -0
- package/lib/typescript/module/push/provider-adapter.d.ts +50 -0
- package/lib/typescript/module/push/provider-adapter.d.ts.map +1 -0
- package/lib/typescript/module/push/signout.d.ts +33 -0
- package/lib/typescript/module/push/signout.d.ts.map +1 -0
- package/lib/typescript/module/reconcile/chunk.d.ts +24 -0
- package/lib/typescript/module/reconcile/chunk.d.ts.map +1 -0
- package/lib/typescript/module/reconcile/diff.d.ts +54 -0
- package/lib/typescript/module/reconcile/diff.d.ts.map +1 -0
- package/lib/typescript/module/reconcile/duplicates.d.ts +32 -0
- package/lib/typescript/module/reconcile/duplicates.d.ts.map +1 -0
- package/lib/typescript/module/reconcile/index.d.ts +35 -0
- package/lib/typescript/module/reconcile/index.d.ts.map +1 -0
- package/lib/typescript/module/reconcile/truncate.d.ts +26 -0
- package/lib/typescript/module/reconcile/truncate.d.ts.map +1 -0
- package/lib/typescript/module/recurrence/clock-guard.d.ts +37 -0
- package/lib/typescript/module/recurrence/clock-guard.d.ts.map +1 -0
- package/lib/typescript/module/recurrence/expand.d.ts +75 -0
- package/lib/typescript/module/recurrence/expand.d.ts.map +1 -0
- package/lib/typescript/module/recurrence/index.d.ts +40 -0
- package/lib/typescript/module/recurrence/index.d.ts.map +1 -0
- package/lib/typescript/module/repeat/expiry.d.ts +23 -0
- package/lib/typescript/module/repeat/expiry.d.ts.map +1 -0
- package/lib/typescript/module/repeat/index.d.ts +49 -0
- package/lib/typescript/module/repeat/index.d.ts.map +1 -0
- package/lib/typescript/module/repeat/marker.d.ts +36 -0
- package/lib/typescript/module/repeat/marker.d.ts.map +1 -0
- package/lib/typescript/module/repeat/place.d.ts +39 -0
- package/lib/typescript/module/repeat/place.d.ts.map +1 -0
- package/lib/typescript/module/schedule/anchor.d.ts +118 -0
- package/lib/typescript/module/schedule/anchor.d.ts.map +1 -0
- package/lib/typescript/module/schedule/index.d.ts +40 -0
- package/lib/typescript/module/schedule/index.d.ts.map +1 -0
- package/lib/typescript/module/schedule/partition.d.ts +29 -0
- package/lib/typescript/module/schedule/partition.d.ts.map +1 -0
- package/lib/typescript/module/schedule/resolve-moment.d.ts +35 -0
- package/lib/typescript/module/schedule/resolve-moment.d.ts.map +1 -0
- package/lib/typescript/module/schedule/validate-content.d.ts +42 -0
- package/lib/typescript/module/schedule/validate-content.d.ts.map +1 -0
- package/lib/typescript/module/schedule/validate-identifier.d.ts +30 -0
- package/lib/typescript/module/schedule/validate-identifier.d.ts.map +1 -0
- package/lib/typescript/module/schedule/writer.d.ts +36 -0
- package/lib/typescript/module/schedule/writer.d.ts.map +1 -0
- package/lib/typescript/module/state/caps.d.ts +51 -0
- package/lib/typescript/module/state/caps.d.ts.map +1 -0
- package/lib/typescript/module/state/dedup-ledger.d.ts +21 -0
- package/lib/typescript/module/state/dedup-ledger.d.ts.map +1 -0
- package/lib/typescript/module/state/interaction-buffer.d.ts +30 -0
- package/lib/typescript/module/state/interaction-buffer.d.ts.map +1 -0
- package/lib/typescript/module/state/mmkv-store.d.ts +33 -0
- package/lib/typescript/module/state/mmkv-store.d.ts.map +1 -0
- package/lib/typescript/module/state/permission-history.d.ts +20 -0
- package/lib/typescript/module/state/permission-history.d.ts.map +1 -0
- package/lib/typescript/module/state/record.d.ts +134 -0
- package/lib/typescript/module/state/record.d.ts.map +1 -0
- package/lib/typescript/module/state/reset.d.ts +22 -0
- package/lib/typescript/module/state/reset.d.ts.map +1 -0
- package/lib/typescript/module/state/series-ledger.d.ts +47 -0
- package/lib/typescript/module/state/series-ledger.d.ts.map +1 -0
- package/lib/typescript/module/state/store.d.ts +20 -0
- package/lib/typescript/module/state/store.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/index.d.ts +32 -0
- package/lib/typescript/module/testing/conformance/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/fake-engine.d.ts +91 -0
- package/lib/typescript/module/testing/fake-engine.d.ts.map +1 -0
- package/lib/typescript/module/testing/fake-provider.d.ts +35 -0
- package/lib/typescript/module/testing/fake-provider.d.ts.map +1 -0
- package/lib/typescript/module/testing/faults.d.ts +38 -0
- package/lib/typescript/module/testing/faults.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +22 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/measure.d.ts +59 -0
- package/lib/typescript/module/testing/measure.d.ts.map +1 -0
- package/package.json +74 -23
- package/skills/sdk-rn-notification/SKILL.md +6 -5
- package/src/advanced.ts +35 -0
- package/src/channel/migrate.ts +176 -158
- package/src/channel/tone-map.ts +2 -10
- package/src/contract/errors.ts +7 -0
- package/src/contract/hash.ts +26 -0
- package/src/engine/adapter.ts +21 -1
- package/src/engine/notify-kit/events.ts +155 -0
- package/src/engine/notify-kit/module.ts +148 -0
- package/src/engine/notify-kit/platform/android.ts +172 -0
- package/src/engine/notify-kit/platform/index.ts +55 -0
- package/src/engine/notify-kit/platform/ios.ts +54 -0
- package/src/engine/notify-kit/platform/types.ts +40 -0
- package/src/engine/notify-kit-engine.ts +96 -477
- package/src/index.ts +9 -0
- package/src/notifications.ts +195 -0
- package/src/permission/index.ts +65 -4
- package/src/push/fcm-provider.ts +14 -4
- package/src/push/gate.ts +27 -5
- package/src/reconcile/diff.ts +38 -27
- package/src/reconcile/index.ts +13 -4
- package/src/recurrence/index.ts +2 -1
- package/src/repeat/expiry.ts +2 -6
- package/src/repeat/index.ts +45 -1
- package/src/repeat/marker.ts +1 -22
- package/src/repeat/place.ts +74 -35
- package/src/schedule/index.ts +10 -4
- package/src/schedule/partition.ts +0 -19
- package/src/schedule/validate-identifier.ts +8 -6
- package/src/schedule/writer.ts +13 -4
- package/src/state/caps.ts +28 -3
- package/src/state/permission-history.ts +25 -0
- package/src/state/record.ts +110 -20
- package/src/testing/fake-engine.ts +17 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Recurrence expansion.
|
|
5
|
+
*
|
|
6
|
+
* Written first-party rather than delegated to an RFC 5545 library, because the
|
|
7
|
+
* daylight-saving rules here are specified behaviour (FR-008) rather than a
|
|
8
|
+
* dependency's opinion, and because expansion must be provable with no device.
|
|
9
|
+
*
|
|
10
|
+
* Determinism is the hard requirement: the same rule, anchoring mode, zone, and
|
|
11
|
+
* evaluation moment must produce exactly the same occurrences in the same order
|
|
12
|
+
* on every run and on both platforms. Without that, reconciliation could not be
|
|
13
|
+
* idempotent over a recurring series.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { DIAGNOSTIC_CODES, NotificationError } from "../contract/errors.js";
|
|
17
|
+
import { instantForParts, partsInZone } from "../schedule/anchor.js";
|
|
18
|
+
const pad = (value, width) => String(value).padStart(width, '0');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The calendar slot of an occurrence: the date and clock time the rule asked
|
|
22
|
+
* for, in the frame the series is anchored in. Fixed-width, so comparing two
|
|
23
|
+
* keys as strings compares them in time.
|
|
24
|
+
*/
|
|
25
|
+
export function occurrenceKey(parts) {
|
|
26
|
+
return `${pad(parts.year, 4)}${pad(parts.month, 2)}${pad(parts.day, 2)}T${pad(parts.hour, 2)}${pad(parts.minute, 2)}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Occurrence identity.
|
|
31
|
+
*
|
|
32
|
+
* Derived from the series and the calendar slot, not the instant. Re-expanding
|
|
33
|
+
* the same series produces the same identifiers, which is what lets a refresh
|
|
34
|
+
* recognize an occurrence it already scheduled. Until 0.4.0 the instant was
|
|
35
|
+
* used, so after a time-zone change re-anchoring kept the old identifier while
|
|
36
|
+
* the window refresh derived a new one, and the occurrence was scheduled twice.
|
|
37
|
+
*/
|
|
38
|
+
export function occurrenceId(seriesId, slot) {
|
|
39
|
+
return `${seriesId}#${typeof slot === 'string' ? slot : occurrenceKey(slot)}`;
|
|
40
|
+
}
|
|
41
|
+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
42
|
+
function validatePattern(pattern) {
|
|
43
|
+
const {
|
|
44
|
+
hour,
|
|
45
|
+
minute
|
|
46
|
+
} = pattern;
|
|
47
|
+
if (!Number.isInteger(hour) || hour < 0 || hour > 23) {
|
|
48
|
+
throw new NotificationError(DIAGNOSTIC_CODES.INVALID_RECURRENCE, 'Recurrence hour must be an integer from 0 to 23.', {
|
|
49
|
+
hour
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!Number.isInteger(minute) || minute < 0 || minute > 59) {
|
|
53
|
+
throw new NotificationError(DIAGNOSTIC_CODES.INVALID_RECURRENCE, 'Recurrence minute must be an integer from 0 to 59.', {
|
|
54
|
+
minute
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const interval = pattern.interval ?? 1;
|
|
58
|
+
if (!Number.isInteger(interval) || interval < 1) {
|
|
59
|
+
throw new NotificationError(DIAGNOSTIC_CODES.INVALID_RECURRENCE, 'Recurrence interval must be a positive integer.', {
|
|
60
|
+
interval
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (pattern.kind === 'weekly') {
|
|
64
|
+
if (pattern.weekdays.length === 0) {
|
|
65
|
+
throw new NotificationError(DIAGNOSTIC_CODES.INVALID_RECURRENCE, 'A weekly recurrence must name at least one weekday.');
|
|
66
|
+
}
|
|
67
|
+
for (const day of pattern.weekdays) {
|
|
68
|
+
if (!Number.isInteger(day) || day < 0 || day > 6) {
|
|
69
|
+
throw new NotificationError(DIAGNOSTIC_CODES.INVALID_RECURRENCE, 'Weekdays must be integers from 0 (Sunday) to 6 (Saturday).', {
|
|
70
|
+
day
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (pattern.kind === 'monthlyByDay') {
|
|
76
|
+
if (!Number.isInteger(pattern.dayOfMonth) || pattern.dayOfMonth < 1 || pattern.dayOfMonth > 31) {
|
|
77
|
+
throw new NotificationError(DIAGNOSTIC_CODES.INVALID_RECURRENCE, 'Day of month must be an integer from 1 to 31.', {
|
|
78
|
+
dayOfMonth: pattern.dayOfMonth
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Calendar date in the anchoring zone, carrying the pattern's clock time. */
|
|
85
|
+
function partsFor(date, pattern) {
|
|
86
|
+
return {
|
|
87
|
+
year: date.year,
|
|
88
|
+
month: date.month,
|
|
89
|
+
day: date.day,
|
|
90
|
+
hour: pattern.hour,
|
|
91
|
+
minute: pattern.minute,
|
|
92
|
+
second: 0
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function addDays(parts, days) {
|
|
96
|
+
const shifted = new Date(Date.UTC(parts.year, parts.month - 1, parts.day) + days * MS_PER_DAY);
|
|
97
|
+
return {
|
|
98
|
+
year: shifted.getUTCFullYear(),
|
|
99
|
+
month: shifted.getUTCMonth() + 1,
|
|
100
|
+
day: shifted.getUTCDate(),
|
|
101
|
+
hour: parts.hour,
|
|
102
|
+
minute: parts.minute,
|
|
103
|
+
second: 0
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function weekdayOf(parts) {
|
|
107
|
+
return new Date(Date.UTC(parts.year, parts.month - 1, parts.day)).getUTCDay();
|
|
108
|
+
}
|
|
109
|
+
function daysInMonth(year, month) {
|
|
110
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Expands a rule inside the lookahead window.
|
|
114
|
+
*
|
|
115
|
+
* Bounded by both a duration and a count, because either alone fails: a
|
|
116
|
+
* duration alone lets a frequent series exhaust the platform ceiling, and a
|
|
117
|
+
* count alone leaves an annual series scheduled a decade out.
|
|
118
|
+
*/
|
|
119
|
+
export function expand(input) {
|
|
120
|
+
const {
|
|
121
|
+
rule,
|
|
122
|
+
from,
|
|
123
|
+
lookahead,
|
|
124
|
+
timeZone
|
|
125
|
+
} = input;
|
|
126
|
+
validatePattern(rule.pattern);
|
|
127
|
+
const anchoring = rule.anchoring ?? 'wallClock';
|
|
128
|
+
const horizon = from + lookahead.days * MS_PER_DAY;
|
|
129
|
+
const start = Math.max(rule.startAt ?? from, from);
|
|
130
|
+
const {
|
|
131
|
+
lastEmittedKey
|
|
132
|
+
} = input;
|
|
133
|
+
const occurrences = [];
|
|
134
|
+
let cursor = partsFor(partsInZone(start, timeZone), rule.pattern);
|
|
135
|
+
// Position of the next not-yet-counted occurrence, for count-limited rules.
|
|
136
|
+
let index = input.alreadyEmitted ?? 0;
|
|
137
|
+
let exhausted = false;
|
|
138
|
+
|
|
139
|
+
// Bounded independently of the emit conditions so a pattern that matches
|
|
140
|
+
// nothing (e.g. day 31 in February) can never spin forever.
|
|
141
|
+
const maxIterations = lookahead.days * 2 + 400;
|
|
142
|
+
for (let iteration = 0; iteration < maxIterations; iteration += 1) {
|
|
143
|
+
if (occurrences.length >= lookahead.occurrencesPerSeries) break;
|
|
144
|
+
const candidate = nextCandidate(cursor, rule.pattern, iteration === 0);
|
|
145
|
+
if (candidate === undefined) break;
|
|
146
|
+
cursor = candidate;
|
|
147
|
+
const at = anchoring === 'absolute' ? Date.UTC(cursor.year, cursor.month - 1, cursor.day, cursor.hour, cursor.minute, 0) : instantForParts(cursor, timeZone);
|
|
148
|
+
if (at > horizon) break;
|
|
149
|
+
if (at > start) {
|
|
150
|
+
if (rule.end.kind === 'untilDate' && at > rule.end.until) {
|
|
151
|
+
exhausted = true;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
const key = occurrenceKey(cursor);
|
|
155
|
+
const previouslyEmitted = lastEmittedKey !== undefined && key <= lastEmittedKey;
|
|
156
|
+
if (!previouslyEmitted && rule.end.kind === 'count' && index >= rule.end.count) {
|
|
157
|
+
exhausted = true;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
occurrences.push({
|
|
161
|
+
id: occurrenceId(rule.id, key),
|
|
162
|
+
key,
|
|
163
|
+
seriesId: rule.id,
|
|
164
|
+
at,
|
|
165
|
+
anchoring,
|
|
166
|
+
previouslyEmitted
|
|
167
|
+
});
|
|
168
|
+
if (!previouslyEmitted) index += 1;
|
|
169
|
+
}
|
|
170
|
+
cursor = advance(cursor, rule.pattern);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
occurrences,
|
|
174
|
+
expandedThrough: horizon,
|
|
175
|
+
exhausted
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Moves the cursor onto the first date the pattern actually matches. */
|
|
180
|
+
function nextCandidate(cursor, pattern, isFirst) {
|
|
181
|
+
if (pattern.kind === 'daily') return cursor;
|
|
182
|
+
if (pattern.kind === 'weekly') {
|
|
183
|
+
const wanted = new Set(pattern.weekdays);
|
|
184
|
+
let candidate = cursor;
|
|
185
|
+
for (let step = 0; step < 14; step += 1) {
|
|
186
|
+
if (wanted.has(weekdayOf(candidate))) return candidate;
|
|
187
|
+
candidate = addDays(candidate, 1);
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
const monthly = pattern;
|
|
192
|
+
let candidate = cursor;
|
|
193
|
+
// Months shorter than the requested day are skipped rather than clamped: a
|
|
194
|
+
// caller asking for the 31st means the 31st, and inventing the 28th would be
|
|
195
|
+
// the package deciding something it was not asked to decide.
|
|
196
|
+
for (let step = 0; step < 48; step += 1) {
|
|
197
|
+
if (daysInMonth(candidate.year, candidate.month) >= monthly.dayOfMonth) {
|
|
198
|
+
const onDay = {
|
|
199
|
+
...candidate,
|
|
200
|
+
day: monthly.dayOfMonth
|
|
201
|
+
};
|
|
202
|
+
if (isFirst || onDay.day >= candidate.day || step > 0) return onDay;
|
|
203
|
+
}
|
|
204
|
+
candidate = firstOfNextMonth(candidate);
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
function firstOfNextMonth(parts) {
|
|
209
|
+
const month = parts.month === 12 ? 1 : parts.month + 1;
|
|
210
|
+
const year = parts.month === 12 ? parts.year + 1 : parts.year;
|
|
211
|
+
return {
|
|
212
|
+
...parts,
|
|
213
|
+
year,
|
|
214
|
+
month,
|
|
215
|
+
day: 1
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Steps the cursor past the occurrence just produced. */
|
|
220
|
+
function advance(cursor, pattern) {
|
|
221
|
+
const interval = pattern.interval ?? 1;
|
|
222
|
+
if (pattern.kind === 'daily') {
|
|
223
|
+
return addDays(cursor, pattern.interval ?? 1);
|
|
224
|
+
}
|
|
225
|
+
if (pattern.kind === 'weekly') {
|
|
226
|
+
const wanted = [...new Set(pattern.weekdays)].sort((a, b) => a - b);
|
|
227
|
+
const current = weekdayOf(cursor);
|
|
228
|
+
const next = wanted.find(day => day > current);
|
|
229
|
+
|
|
230
|
+
// Wrapping into a new week is where the interval applies — stepping day by
|
|
231
|
+
// day within the week would multiply the interval by the weekday count.
|
|
232
|
+
return next === undefined ? addDays(cursor, 7 * interval - current + wanted[0]) : addDays(cursor, next - current);
|
|
233
|
+
}
|
|
234
|
+
const monthly = pattern;
|
|
235
|
+
let year = cursor.year;
|
|
236
|
+
let month = cursor.month + interval;
|
|
237
|
+
while (month > 12) {
|
|
238
|
+
month -= 12;
|
|
239
|
+
year += 1;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
...cursor,
|
|
243
|
+
year,
|
|
244
|
+
month,
|
|
245
|
+
day: Math.min(monthly.dayOfMonth, daysInMonth(year, month))
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=expand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DIAGNOSTIC_CODES","NotificationError","instantForParts","partsInZone","pad","value","width","String","padStart","occurrenceKey","parts","year","month","day","hour","minute","occurrenceId","seriesId","slot","MS_PER_DAY","validatePattern","pattern","Number","isInteger","INVALID_RECURRENCE","interval","kind","weekdays","length","dayOfMonth","partsFor","date","second","addDays","days","shifted","Date","UTC","getUTCFullYear","getUTCMonth","getUTCDate","weekdayOf","getUTCDay","daysInMonth","expand","input","rule","from","lookahead","timeZone","anchoring","horizon","start","Math","max","startAt","lastEmittedKey","occurrences","cursor","index","alreadyEmitted","exhausted","maxIterations","iteration","occurrencesPerSeries","candidate","nextCandidate","undefined","at","end","until","key","previouslyEmitted","count","push","id","advance","expandedThrough","isFirst","wanted","Set","step","has","monthly","onDay","firstOfNextMonth","sort","a","b","current","next","find","min"],"sourceRoot":"../../../src","sources":["recurrence/expand.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASA,gBAAgB,EAAEC,iBAAiB,QAAQ,uBAAoB;AACxE,SAASC,eAAe,EAAEC,WAAW,QAA6B,uBAAoB;AActF,MAAMC,GAAG,GAAGA,CAACC,KAAa,EAAEC,KAAa,KAAKC,MAAM,CAACF,KAAK,CAAC,CAACG,QAAQ,CAACF,KAAK,EAAE,GAAG,CAAC;;AAEhF;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,aAAaA,CAACC,KAAqB,EAAU;EAC5D,OAAO,GAAGN,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,CAAC,CAAC,GAAGP,GAAG,CAACM,KAAK,CAACE,KAAK,EAAE,CAAC,CAAC,GAAGR,GAAG,CAACM,KAAK,CAACG,GAAG,EAAE,CAAC,CAAC,IAAIT,GAAG,CAACM,KAAK,CAACI,IAAI,EAAE,CAAC,CAAC,GAAGV,GAAG,CAACM,KAAK,CAACK,MAAM,EAAE,CAAC,CAAC,EAAE;AACtH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,QAAgB,EAAEC,IAA6B,EAAU;EACrF,OAAO,GAAGD,QAAQ,IAAI,OAAOC,IAAI,KAAK,QAAQ,GAAGA,IAAI,GAAGT,aAAa,CAACS,IAAI,CAAC,EAAE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CAAC,GAAGC,CAAC,CAAC;IACtF,MAAMC,OAAO,GAAGhD,SAAS,CAACiB,MAAM,CAAC;IACjC,MAAMgC,IAAI,GAAGX,MAAM,CAACY,IAAI,CAAC9E,GAAG,IAAIA,GAAG,GAAG4E,OAAO,CAAC;;IAE9C;IACA;IACA,OAAOC,IAAI,KAAKvB,SAAS,GACtBlC,OAAO,CAACyB,MAAM,EAAE,CAAC,GAAGjC,QAAQ,GAAGgE,OAAO,GAAGV,MAAM,CAAC,CAAC,CAAC,CAAC,GACnD9C,OAAO,CAACyB,MAAM,EAAEgC,IAAI,GAAGD,OAAO,CAAC;EACnC;EAEA,MAAMN,OAAO,GAAG9D,OAA8B;EAC9C,IAAIV,IAAI,GAAG+C,MAAM,CAAC/C,IAAI;EACtB,IAAIC,KAAK,GAAG8C,MAAM,CAAC9C,KAAK,GAAGa,QAAQ;EACnC,OAAOb,KAAK,GAAG,EAAE,EAAE;IAClBA,KAAK,IAAI,EAAE;IACXD,IAAI,IAAI,CAAC;EACV;EACA,OAAO;IAAE,GAAG+C,MAAM;IAAE/C,IAAI;IAAEC,KAAK;IAAEC,GAAG,EAAEwC,IAAI,CAACuC,GAAG,CAACT,OAAO,CAACtD,UAAU,EAAEc,WAAW,CAAChC,IAAI,EAAEC,KAAK,CAAC;EAAE,CAAC;AAC/F","ignoreList":[]}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Series registration and the lookahead window.
|
|
5
|
+
*
|
|
6
|
+
* A caller declares a rule once. The package expands it inside a finite window
|
|
7
|
+
* and refreshes that window on its own, because only it knows when the horizon
|
|
8
|
+
* has moved — that is the one piece of recurrence knowledge the consumer does
|
|
9
|
+
* not have.
|
|
10
|
+
*
|
|
11
|
+
* Occurrences carry derived identifiers, so re-expanding a series recognises
|
|
12
|
+
* what it already scheduled instead of creating duplicates. That is what makes
|
|
13
|
+
* a window refresh with nothing to do cost zero platform operations.
|
|
14
|
+
*
|
|
15
|
+
* Occurrences are written through the shared `ScheduleWriter`, like every other
|
|
16
|
+
* consumer notification, so a repeating tone gets its stop marker and the
|
|
17
|
+
* platform ceiling is respected here too.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { partsInZone } from "../schedule/anchor.js";
|
|
21
|
+
import { validateIdentifier } from "../schedule/validate-identifier.js";
|
|
22
|
+
import { validateRequest } from "../schedule/index.js";
|
|
23
|
+
import { createScheduleWriter } from "../schedule/writer.js";
|
|
24
|
+
import { DIAGNOSTIC_CODES, NotificationError } from "../contract/errors.js";
|
|
25
|
+
import { expand, occurrenceKey } from "./expand.js";
|
|
26
|
+
import { guardAgainstClockChange } from "./clock-guard.js";
|
|
27
|
+
import { listSeries as readLedger, readSeries, removeSeries, upsertSeries } from "../state/series-ledger.js";
|
|
28
|
+
/** Builds the request for one occurrence from the series template. */
|
|
29
|
+
function toRequest(rule, occurrence) {
|
|
30
|
+
return {
|
|
31
|
+
id: occurrence.id,
|
|
32
|
+
content: rule.template.content,
|
|
33
|
+
tone: rule.template.tone,
|
|
34
|
+
moment: {
|
|
35
|
+
at: occurrence.at,
|
|
36
|
+
anchoring: occurrence.anchoring
|
|
37
|
+
},
|
|
38
|
+
routing: rule.template.routing,
|
|
39
|
+
actions: rule.template.actions,
|
|
40
|
+
ownerTag: rule.template.ownerTag,
|
|
41
|
+
groupTag: rule.template.groupTag
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const belongsTo = (entry, seriesId) => entry.seriesId === seriesId || entry.id.startsWith(`${seriesId}#`);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The latest occurrence a ledger entry written before 0.4.0 had emitted. Those
|
|
48
|
+
* entries kept no key, so it is read back off the device: the last occurrence
|
|
49
|
+
* still pending is the last one emitted.
|
|
50
|
+
*/
|
|
51
|
+
function recoverLastEmittedKey(pending, anchoring, zone) {
|
|
52
|
+
if (pending.length === 0) return undefined;
|
|
53
|
+
const latest = Math.max(...pending.map(entry => entry.resolvedAt));
|
|
54
|
+
return occurrenceKey(partsInZone(latest, anchoring === 'absolute' ? 'UTC' : zone));
|
|
55
|
+
}
|
|
56
|
+
export function createRecurrence(deps) {
|
|
57
|
+
const emit = deps.emit ?? (() => {});
|
|
58
|
+
const writer = createScheduleWriter(deps.engine);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Validates the template as the request every occurrence will be, once, so
|
|
62
|
+
* a series is refused at registration for exactly what a direct schedule
|
|
63
|
+
* would be refused for — an undeclared tone, too many actions, an oversized
|
|
64
|
+
* routing payload — rather than failing later inside maintenance.
|
|
65
|
+
*/
|
|
66
|
+
const validateTemplate = rule => validateRequest({
|
|
67
|
+
id: rule.id,
|
|
68
|
+
content: rule.template.content,
|
|
69
|
+
tone: rule.template.tone,
|
|
70
|
+
moment: {
|
|
71
|
+
at: deps.now(),
|
|
72
|
+
anchoring: rule.anchoring ?? 'wallClock'
|
|
73
|
+
},
|
|
74
|
+
routing: rule.template.routing,
|
|
75
|
+
actions: rule.template.actions,
|
|
76
|
+
ownerTag: rule.template.ownerTag,
|
|
77
|
+
groupTag: rule.template.groupTag
|
|
78
|
+
}, deps.resolveTone);
|
|
79
|
+
const toneFor = rule => {
|
|
80
|
+
const tone = deps.resolveTone(rule.template.tone);
|
|
81
|
+
if (tone === undefined) {
|
|
82
|
+
throw new NotificationError(DIAGNOSTIC_CODES.UNDECLARED_TONE, `Tone "${rule.template.tone}" was never declared in the package configuration.`, {
|
|
83
|
+
toneId: rule.template.tone,
|
|
84
|
+
seriesId: rule.id
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return tone;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Expands and registers, scheduling only occurrences the device lacks. */
|
|
91
|
+
const materialize = async (rule, tone) => {
|
|
92
|
+
const now = deps.now();
|
|
93
|
+
const zone = deps.timeZone();
|
|
94
|
+
const previous = readSeries(deps.state, rule.id);
|
|
95
|
+
const pending = await deps.engine.getPending();
|
|
96
|
+
const ofSeries = pending.filter(entry => belongsTo(entry, rule.id));
|
|
97
|
+
const expansion = expand({
|
|
98
|
+
rule,
|
|
99
|
+
from: now,
|
|
100
|
+
lookahead: deps.lookahead,
|
|
101
|
+
timeZone: zone,
|
|
102
|
+
alreadyEmitted: previous?.emittedCount ?? 0,
|
|
103
|
+
lastEmittedKey: previous?.lastEmittedKey ?? (previous !== undefined ? recoverLastEmittedKey(ofSeries, rule.anchoring, zone) : undefined)
|
|
104
|
+
});
|
|
105
|
+
const guarded = guardAgainstClockChange({
|
|
106
|
+
occurrences: expansion.occurrences,
|
|
107
|
+
previousHorizon: previous?.expandedThrough,
|
|
108
|
+
now,
|
|
109
|
+
previousNow: previous?.at
|
|
110
|
+
});
|
|
111
|
+
if (guarded.discontinuity !== 'none') {
|
|
112
|
+
emit('CLOCK_DISCONTINUITY', `Device clock moved ${guarded.discontinuity}; ${guarded.suppressed} already-handled occurrence(s) were suppressed rather than re-delivered.`, {
|
|
113
|
+
direction: guarded.discontinuity,
|
|
114
|
+
suppressed: guarded.suppressed,
|
|
115
|
+
seriesId: rule.id
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const wanted = new Set(guarded.occurrences.map(occurrence => occurrence.id));
|
|
119
|
+
|
|
120
|
+
// Upcoming entries of this series the expansion no longer produces: ones
|
|
121
|
+
// written under the instant-based identity before 0.4.0, or ones whose slot
|
|
122
|
+
// the rule no longer has. Left in place, each would fire beside its
|
|
123
|
+
// replacement. Entries already due are left alone — they may be firing now.
|
|
124
|
+
const stale = ofSeries.filter(entry => !wanted.has(entry.id) && entry.resolvedAt > now);
|
|
125
|
+
for (const entry of stale) {
|
|
126
|
+
await writer.cancel(entry.id);
|
|
127
|
+
}
|
|
128
|
+
const onDevice = new Set(ofSeries.filter(entry => !stale.includes(entry)).map(entry => entry.id));
|
|
129
|
+
const missing = guarded.occurrences.filter(occurrence => !onDevice.has(occurrence.id));
|
|
130
|
+
|
|
131
|
+
// The same ceiling reconciliation respects: soonest first, the rest
|
|
132
|
+
// registered by a later refresh once they move into range.
|
|
133
|
+
const room = Math.max(0, (await writer.capacity()) - (pending.length - stale.length));
|
|
134
|
+
const toSchedule = missing.slice(0, room);
|
|
135
|
+
if (toSchedule.length < missing.length) {
|
|
136
|
+
emit(DIAGNOSTIC_CODES.TRUNCATED_OVER_CEILING, `Series "${rule.id}" has ${missing.length - toSchedule.length} occurrence(s) beyond the platform ceiling; they are registered by a later window refresh.`, {
|
|
137
|
+
seriesId: rule.id,
|
|
138
|
+
dropped: missing.length - toSchedule.length
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const approximate = !deps.canScheduleExactly();
|
|
142
|
+
for (const occurrence of toSchedule) {
|
|
143
|
+
await writer.write({
|
|
144
|
+
request: toRequest(rule, occurrence),
|
|
145
|
+
resolvedAt: occurrence.at,
|
|
146
|
+
tone,
|
|
147
|
+
// The zone the series was expanded against; absent for absolute series.
|
|
148
|
+
anchoringGeneration: occurrence.anchoring === 'absolute' ? undefined : zone,
|
|
149
|
+
approximate,
|
|
150
|
+
seriesId: rule.id
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Counted once, when first emitted — whether or not the ceiling let it on
|
|
155
|
+
// the device yet. Occurrences re-produced from an earlier expansion are not
|
|
156
|
+
// counted again.
|
|
157
|
+
const newlyEmitted = guarded.occurrences.filter(occurrence => !occurrence.previouslyEmitted);
|
|
158
|
+
const lastEmittedKey = newlyEmitted.length > 0 ? newlyEmitted[newlyEmitted.length - 1].key : previous?.lastEmittedKey;
|
|
159
|
+
upsertSeries(deps.state, rule, {
|
|
160
|
+
expandedThrough: expansion.expandedThrough,
|
|
161
|
+
emittedCount: (previous?.emittedCount ?? 0) + newlyEmitted.length,
|
|
162
|
+
exhausted: expansion.exhausted,
|
|
163
|
+
lastEmittedKey
|
|
164
|
+
}, now);
|
|
165
|
+
return {
|
|
166
|
+
seriesId: rule.id,
|
|
167
|
+
scheduled: toSchedule.length,
|
|
168
|
+
expandedThrough: expansion.expandedThrough,
|
|
169
|
+
exhausted: expansion.exhausted,
|
|
170
|
+
cancelled: stale.map(entry => entry.id)
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
async registerSeries(rule) {
|
|
175
|
+
validateIdentifier(rule.id, 'seriesId');
|
|
176
|
+
return materialize(rule, validateTemplate(rule));
|
|
177
|
+
},
|
|
178
|
+
/** Re-expands a tracked series. Called by the window-refresh maintenance step. */
|
|
179
|
+
async refreshSeries(rule) {
|
|
180
|
+
return materialize(rule, toneFor(rule));
|
|
181
|
+
},
|
|
182
|
+
async cancelSeries(seriesId) {
|
|
183
|
+
validateIdentifier(seriesId, 'seriesId');
|
|
184
|
+
|
|
185
|
+
// Every occurrence already scheduled from this series goes, identified by
|
|
186
|
+
// its derived prefix rather than by a list the ledger would have to keep
|
|
187
|
+
// in sync with the device.
|
|
188
|
+
const pending = await deps.engine.getPending();
|
|
189
|
+
const ids = pending.filter(entry => belongsTo(entry, seriesId)).map(entry => entry.id);
|
|
190
|
+
await deps.engine.cancelMany(ids);
|
|
191
|
+
const pass = writer.pass();
|
|
192
|
+
for (const id of ids) await pass.releaseStop(id);
|
|
193
|
+
removeSeries(deps.state, seriesId);
|
|
194
|
+
return ids;
|
|
195
|
+
},
|
|
196
|
+
async listSeries() {
|
|
197
|
+
const pending = await deps.engine.getPending();
|
|
198
|
+
return readLedger(deps.state).map(entry => ({
|
|
199
|
+
seriesId: entry.seriesId,
|
|
200
|
+
anchoring: entry.anchoring,
|
|
201
|
+
expandedThrough: entry.expandedThrough,
|
|
202
|
+
pendingOccurrences: pending.filter(p => belongsTo(p, entry.seriesId)).length,
|
|
203
|
+
exhausted: entry.exhausted
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["partsInZone","validateIdentifier","validateRequest","createScheduleWriter","DIAGNOSTIC_CODES","NotificationError","expand","occurrenceKey","guardAgainstClockChange","listSeries","readLedger","readSeries","removeSeries","upsertSeries","toRequest","rule","occurrence","id","content","template","tone","moment","at","anchoring","routing","actions","ownerTag","groupTag","belongsTo","entry","seriesId","startsWith","recoverLastEmittedKey","pending","zone","length","undefined","latest","Math","max","map","resolvedAt","createRecurrence","deps","emit","writer","engine","validateTemplate","now","resolveTone","toneFor","UNDECLARED_TONE","toneId","materialize","timeZone","previous","state","getPending","ofSeries","filter","expansion","from","lookahead","alreadyEmitted","emittedCount","lastEmittedKey","guarded","occurrences","previousHorizon","expandedThrough","previousNow","discontinuity","suppressed","direction","wanted","Set","stale","has","cancel","onDevice","includes","missing","room","capacity","toSchedule","slice","TRUNCATED_OVER_CEILING","dropped","approximate","canScheduleExactly","write","request","anchoringGeneration","newlyEmitted","previouslyEmitted","key","exhausted","scheduled","cancelled","registerSeries","refreshSeries","cancelSeries","ids","cancelMany","pass","releaseStop","pendingOccurrences","p"],"sourceRoot":"../../../src","sources":["recurrence/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASA,WAAW,QAA6B,uBAAoB;AACrE,SAASC,kBAAkB,QAAQ,oCAAiC;AACpE,SAASC,eAAe,QAAQ,sBAAa;AAC7C,SAASC,oBAAoB,QAAQ,uBAAoB;AACzD,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,uBAAoB;AACxE,SAASC,MAAM,EAAEC,aAAa,QAAyB,aAAU;AACjE,SAASC,uBAAuB,QAAQ,kBAAe;AACvD,SACCC,UAAU,IAAIC,UAAU,EACxBC,UAAU,EACVC,YAAY,EACZC,YAAY,QACN,2BAAwB;AAa/B;AACA,SAASC,SAASA,CAACC,IAAoB,EAAEC,UAAsB,EAAuB;EACrF,OAAO;IACNC,EAAE,EAAED,UAAU,CAACC,EAAE;IACjBC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,CAAC,CAAChB,GAAG,CAACX,KAAK,KAAK;QAC3CC,QAAQ,EAAED,KAAK,CAACC,QAAQ;QACxBP,SAAS,EAAEM,KAAK,CAACN,SAAS;QAC1B8C,eAAe,EAAExC,KAAK,CAACwC,eAAe;QACtCqC,kBAAkB,EAAEzE,OAAO,CAAC0B,MAAM,CAACgD,CAAC,IAAI/E,SAAS,CAAC+E,CAAC,EAAE9E,KAAK,CAACC,QAAQ,CAAC,CAAC,CAACK,MAAM;QAC5E6D,SAAS,EAAEnE,KAAK,CAACmE;MAClB,CAAC,CAAC,CAAC;IACJ;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Repeat expiry.
|
|
5
|
+
*
|
|
6
|
+
* When a stop marker is delivered, the alert it guards has run its declared
|
|
7
|
+
* course. This handler ends the sound and leaves the notification exactly where
|
|
8
|
+
* it is, then removes the marker.
|
|
9
|
+
*
|
|
10
|
+
* Nothing here imports the engine. It talks to the port, which is what lets the
|
|
11
|
+
* whole mechanism be proven on a virtual clock with no device.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createStopPlacement } from "./place.js";
|
|
15
|
+
export function createRepeatExpiryHandler(deps) {
|
|
16
|
+
return {
|
|
17
|
+
async handle(event) {
|
|
18
|
+
const stop = event.repeatStop;
|
|
19
|
+
if (stop === undefined) return;
|
|
20
|
+
|
|
21
|
+
// Order matters. Silence first, remove the marker second: if the
|
|
22
|
+
// process dies between the two, a marker left behind is harmless
|
|
23
|
+
// noise, whereas a device left sounding is the failure this exists to
|
|
24
|
+
// prevent.
|
|
25
|
+
//
|
|
26
|
+
// `silenceDelivered` returning false is the ordinary case, not an
|
|
27
|
+
// error — it means the user already handled the notification. Checking
|
|
28
|
+
// the tray rather than racing to cancel the marker on interaction is
|
|
29
|
+
// what makes early handling correct by construction: even if the marker
|
|
30
|
+
// fires, there is nothing left to act on.
|
|
31
|
+
await deps.engine.silenceDelivered(stop.targetId);
|
|
32
|
+
await deps.engine.cancel(stop.markerId);
|
|
33
|
+
},
|
|
34
|
+
release: targetId => createStopPlacement(deps.engine).release(targetId)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=expiry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createStopPlacement","createRepeatExpiryHandler","deps","handle","event","stop","repeatStop","undefined","engine","silenceDelivered","targetId","cancel","markerId","release"],"sourceRoot":"../../../src","sources":["repeat/expiry.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,mBAAmB,QAAQ,YAAS;AAc7C,OAAO,SAASC,yBAAyBA,CAACC,IAA8B,EAAuB;EAC9F,OAAO;IACN,MAAMC,MAAMA,CAACC,KAAoB,EAAiB;MACjD,MAAMC,IAAI,GAAGD,KAAK,CAACE,UAAU;MAC7B,IAAID,IAAI,KAAKE,SAAS,EAAE;;MAExB;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,MAAML,IAAI,CAACM,MAAM,CAACC,gBAAgB,CAACJ,IAAI,CAACK,QAAQ,CAAC;MACjD,MAAMR,IAAI,CAACM,MAAM,CAACG,MAAM,CAACN,IAAI,CAACO,QAAQ,CAAC;IACxC,CAAC;IAEDC,OAAO,EAAEH,QAAQ,IAAIV,mBAAmB,CAACE,IAAI,CAACM,MAAM,CAAC,CAACK,OAAO,CAACH,QAAQ;EACvE,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Repeat expiry — bounding an alert that repeats until it is handled.
|
|
5
|
+
*
|
|
6
|
+
* The one piece of this package a consumer has to wire up themselves. The
|
|
7
|
+
* engine registers its background task at module scope, outside the React tree,
|
|
8
|
+
* and no library can perform that registration on an app's behalf.
|
|
9
|
+
*
|
|
10
|
+
* An app that declares no repeating tone needs none of this.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { buffer } from "../state/interaction-buffer.js";
|
|
14
|
+
import { StateManager } from "../state/record.js";
|
|
15
|
+
import { createRepeatExpiryHandler } from "./expiry.js";
|
|
16
|
+
export { createRepeatExpiryHandler } from "./expiry.js";
|
|
17
|
+
export { REPEAT_STOP_PREFIX, isRepeatStopId, markerIdFor, repeatStopFor } from "./marker.js";
|
|
18
|
+
/**
|
|
19
|
+
* Registers the handler that ends a repeating alert while the app is dead.
|
|
20
|
+
*
|
|
21
|
+
* Call this at module scope in `index.js`, beside the app registration — not
|
|
22
|
+
* inside a component, and not inside an effect. By the time a component mounts,
|
|
23
|
+
* the process that needed this handler has already been asked to run it.
|
|
24
|
+
*
|
|
25
|
+
* Without it a repeating alert still starts and still stops when the user
|
|
26
|
+
* handles it, but nothing ends it on a device left face-down on a table. That
|
|
27
|
+
* is the whole reason the feature exists, so `apply()` reports its absence
|
|
28
|
+
* rather than letting anyone find out the hard way.
|
|
29
|
+
*/
|
|
30
|
+
export function registerBackgroundNotificationHandler(registration) {
|
|
31
|
+
const handler = createRepeatExpiryHandler(registration);
|
|
32
|
+
const keep = event => {
|
|
33
|
+
if (registration.store === undefined) return;
|
|
34
|
+
// A manager of its own: this runs in a process with no runtime, and the
|
|
35
|
+
// runtime created later loads what is written here.
|
|
36
|
+
buffer(new StateManager({
|
|
37
|
+
store: registration.store,
|
|
38
|
+
now: registration.now ?? (() => Date.now())
|
|
39
|
+
}), event);
|
|
40
|
+
};
|
|
41
|
+
registration.engine.registerBackgroundDeliveryHandler(event => handler.handle(event), async event => {
|
|
42
|
+
if (registration.onInteraction === undefined) {
|
|
43
|
+
keep(event);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await registration.onInteraction(event);
|
|
48
|
+
} catch {
|
|
49
|
+
// The app's handler failed; the interaction is kept rather than lost.
|
|
50
|
+
keep(event);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Both paths, not just the background one. The engine routes a delivery to
|
|
55
|
+
// the foreground listener while the app is alive and to the headless task
|
|
56
|
+
// only when it is not — so registering only the latter leaves the alert
|
|
57
|
+
// sounding for anyone holding the phone when the window runs out, which is
|
|
58
|
+
// the one case they would certainly notice.
|
|
59
|
+
registration.engine.subscribeToDeliveries(event => {
|
|
60
|
+
// Deliberately not awaited: the engine's foreground listener is
|
|
61
|
+
// synchronous, and a rejection here must not take the subscription down
|
|
62
|
+
// with it — a handler that stopped listening would leave every later
|
|
63
|
+
// alarm unbounded.
|
|
64
|
+
handler.handle(event).catch(() => {});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["buffer","StateManager","createRepeatExpiryHandler","REPEAT_STOP_PREFIX","isRepeatStopId","markerIdFor","repeatStopFor","registerBackgroundNotificationHandler","registration","handler","keep","event","store","undefined","now","Date","engine","registerBackgroundDeliveryHandler","handle","onInteraction","subscribeToDeliveries","catch"],"sourceRoot":"../../../src","sources":["repeat/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,MAAM,QAAQ,gCAA6B;AACpD,SAASC,YAAY,QAAQ,oBAAiB;AAE9C,SAASC,yBAAyB,QAAQ,aAAU;AAEpD,SAASA,yBAAyB,QAAQ,aAAU;AAEpD,SAASC,kBAAkB,EAAEC,cAAc,EAAEC,WAAW,EAAEC,aAAa,QAAQ,aAAU;AAuBzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qCAAqCA,CACpDC,YAA2C,EACpC;EACP,MAAMC,OAAO,GAAGP,yBAAyB,CAACM,YAAY,CAAC;EAEvD,MAAME,IAAI,GAAIC,KAAuB,IAAW;IAC/C,IAAIH,YAAY,CAACI,KAAK,KAAKC,SAAS,EAAE;IACtC;IACA;IACAb,MAAM,CACL,IAAIC,YAAY,CAAC;MAAEW,KAAK,EAAEJ,YAAY,CAACI,KAAK;MAAEE,GAAG,EAAEN,YAAY,CAACM,GAAG,KAAK,MAAMC,IAAI,CAACD,GAAG,CAAC,CAAC;IAAE,CAAC,CAAC,EAC5FH,KACD,CAAC;EACF,CAAC;EAEDH,YAAY,CAACQ,MAAM,CAACC,iCAAiC,CACpDN,KAAK,IAAIF,OAAO,CAACS,MAAM,CAACP,KAAK,CAAC,EAC9B,MAAMA,KAAK,IAAI;IACd,IAAIH,YAAY,CAACW,aAAa,KAAKN,SAAS,EAAE;MAC7CH,IAAI,CAACC,KAAK,CAAC;MACX;IACD;IACA,IAAI;MACH,MAAMH,YAAY,CAACW,aAAa,CAACR,KAAK,CAAC;IACxC,CAAC,CAAC,MAAM;MACP;MACAD,IAAI,CAACC,KAAK,CAAC;IACZ;EACD,CACD,CAAC;;EAED;EACA;EACA;EACA;EACA;EACAH,YAAY,CAACQ,MAAM,CAACI,qBAAqB,CAACT,KAAK,IAAI;IAClD;IACA;IACA;IACA;IACAF,OAAO,CAACS,MAAM,CAACP,KAAK,CAAC,CAACU,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;EACtC,CAAC,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stop-marker identity.
|
|
5
|
+
*
|
|
6
|
+
* A repeating alert has to end without the app being alive, and no platform
|
|
7
|
+
* offers "stop the sound at time T but keep the notification". So the package
|
|
8
|
+
* schedules its own notification at T and reacts to its delivery. That
|
|
9
|
+
* notification is a *marker*: it exists to be delivered and immediately
|
|
10
|
+
* removed, never to be read.
|
|
11
|
+
*
|
|
12
|
+
* The marker's identifier is derived from the target's by hashing rather than by
|
|
13
|
+
* concatenation. Concatenation would overflow the package's 128-character
|
|
14
|
+
* identifier limit for any target already near it, and would make the marker's
|
|
15
|
+
* identity a function of a value the consumer controls — which is how a
|
|
16
|
+
* consumer identifier ends up colliding with an internal one.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { fnv1a, hex8 } from "../contract/hash.js";
|
|
20
|
+
/**
|
|
21
|
+
* Reserved identifier namespace.
|
|
22
|
+
*
|
|
23
|
+
* Rejected as a consumer identifier prefix. A consumer id colliding with a
|
|
24
|
+
* marker would not merely confuse a listing: the expiry handler cancels
|
|
25
|
+
* markers, so the collision would delete a real notification.
|
|
26
|
+
*/
|
|
27
|
+
export const REPEAT_STOP_PREFIX = 'cms.stop:';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The marker identifier for a target notification.
|
|
31
|
+
*
|
|
32
|
+
* Two independent hashes rather than one: a single 32-bit hash collides often
|
|
33
|
+
* enough to matter once a device holds a handful of alarms, and a collision here
|
|
34
|
+
* means one alarm's marker silences the other alarm and never silences its own.
|
|
35
|
+
*/
|
|
36
|
+
export function markerIdFor(targetId) {
|
|
37
|
+
return `${REPEAT_STOP_PREFIX}${hex8(fnv1a(targetId, 0x811c9dc5))}${hex8(fnv1a(targetId, 0x9e3779b9))}`;
|
|
38
|
+
}
|
|
39
|
+
export function isRepeatStopId(id) {
|
|
40
|
+
return id.startsWith(REPEAT_STOP_PREFIX);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Describes the stop for a target whose alert must end at a known instant. */
|
|
44
|
+
export function repeatStopFor(targetId, deliveredAt, forMs) {
|
|
45
|
+
return {
|
|
46
|
+
markerId: markerIdFor(targetId),
|
|
47
|
+
targetId,
|
|
48
|
+
dueAt: deliveredAt + forMs
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=marker.js.map
|