Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/general-issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: General issue
about: Report a reproducible bug or issue
title: '[Bug] [Feature Request] Short description of the issue'
labels: ''
assignees: ''
---

## 🐞 Expected Behavior
<!-- Describe what should happen under normal conditions. -->

## ❌ Actual Behavior
<!-- Describe what is currently happening instead of the expected behavior. -->

## 🔄 Steps to Reproduce
1. <!-- Step 1: Provide clear instructions to reproduce the issue. -->
2. <!-- Step 2: Add any additional steps as needed. -->
3. <!-- Continue listing steps until the issue is fully reproducible. -->

## 📄 Logs / Error Messages
<!-- Paste any relevant logs, error messages, or stack traces. -->

## 📸 Screenshots
<!-- Attach screenshots or GIFs that help visualize the issue. -->

## 💻 Code Snippets
```swift
// Include relevant code snippets that help reproduce the issue.
```

## 🛠 System Information
- **Package Version**: <!-- e.g., 0.1.0 -->
- **Operating System**: <!-- e.g., macOS 14, iOS 18 -->
- **Device / Hardware**: <!-- e.g., iPhone 14 Pro, M1 MacBook -->
8 changes: 8 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## What
<!-- What was changed -->

## Why
<!-- Why this change was needed -->

## Changes
<!-- List affected files/modules -->
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on:
pull_request:
branches: [ main ]

jobs:
test:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

- name: List available iOS runtimes
run: xcrun simctl list runtimes

- name: Create and boot iOS Simulator
run: |
# Get the latest iOS runtime available
RUNTIME=$(xcrun simctl list runtimes | grep "iOS" | tail -1 | grep -oE "com\.apple\.CoreSimulator\.SimRuntime\.iOS-[0-9-]+")
echo "Using runtime: $RUNTIME"

# Create simulator
SIMULATOR_ID=$(xcrun simctl create test-device com.apple.CoreSimulator.SimDeviceType.iPhone-15 "$RUNTIME" 2>&1 | tail -1)
echo "Created simulator: $SIMULATOR_ID"

# Boot it
xcrun simctl boot "$SIMULATOR_ID"

# Wait for it to boot
sleep 5

echo "SIMULATOR_ID=$SIMULATOR_ID" >> $GITHUB_ENV

- name: Run tests with iOS Simulator
run: |
xcodebuild test \
-scheme ZeplinPersistence \
-skipPackagePluginValidation \
-destination "id=${{ env.SIMULATOR_ID }}" \
-derivedDataPath .build \
-enableCodeCoverage YES \
-sdk iphonesimulator \
-verbose
5 changes: 5 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
builder:
configs:
- documentation_targets: [ZeplinPersistence]
platform: ios
70 changes: 70 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentConditionalCompilationBlocks" : true,
"indentSwitchCaseLabels" : false,
"indentation" : {
"spaces" : 4
},
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 140,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : true,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : true,
"tabWidth" : 4,
"version" : 1
}
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.1.0] - 2026-01-12

First public release of ZeplinPersistence.

### Added
- Documentation comments for all public APIs
- DocC documentation with package overview
- Comprehensive README with installation and usage examples
- MIT License
- Swift Package Index configuration
- GitHub Actions CI workflow for running tests
- Issue and pull request templates
- Basic XCTest suite for CoreData persistence
- SwiftFormat lint plugin for code consistency

## [0.0.2] - 2025-01-12

### Changed
- Updated to Fetcher v0.0.2 and ZeplinKit v0.0.3
- Made AppTarget conform to Sendable for Swift concurrency

## [0.0.1] - 2025-01-12

Initial internal release.

### Added
- PersistenceController for managing CoreData stack with app group support
- TokenRepository actor for secure keychain-based token management
- NotificationRecord entity with CoreData model
- AppTarget enum for configuring different app targets
- Support for iOS, macOS, and watchOS platforms
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Snapp-Mobile

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 8 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ZeplinPersistence",
platforms: [
.iOS(.v14),
.macOS(.v11)
.macOS(.v11),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ZeplinPersistence",
targets: ["ZeplinPersistence"]
),
)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Snapp-Mobile/Fetcher", from: "0.0.2"),
.package(url: "https://github.com/Snapp-Mobile/ZeplinKit", from: "0.0.3"),
.package(url: "https://github.com/jrendel/SwiftKeychainWrapper", from: "4.0.0"),
.package(url: "https://github.com/Snapp-Mobile/SwiftFormatLintPlugin.git", from: "1.0.4"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ZeplinPersistence",
dependencies: ["ZeplinKit", "Fetcher", "SwiftKeychainWrapper"]),
dependencies: ["ZeplinKit", "Fetcher", "SwiftKeychainWrapper"],
plugins: [.plugin(name: "Lint", package: "SwiftFormatLintPlugin")],
),
.testTarget(
name: "ZeplinPersistenceTests",
dependencies: ["ZeplinPersistence"]),
dependencies: ["ZeplinPersistence"]
),
]
)
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
<div align="center">
<img src="Sources/ZeplinPersistence/ZeplinPersistence.docc/Resources/ZeplinPersistance-logo.png" width="200" alt="ZeplinPersistence Logo">
</div>

# ZeplinPersistence

A Swift Package that wraps up a CoreData container for persisting user's notifications

[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FSnapp-Mobile%2FZeplinPersistence%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Snapp-Mobile/ZeplinPersistence)
[![iOS 13.0+](https://img.shields.io/badge/iOS-13.0+-007AFF?logo=apple&logoColor=white)](https://www.apple.com/ios/)
[![Latest Release](https://img.shields.io/github/v/release/Snapp-Mobile/ZeplinPersistence?color=8B5CF6&logo=github&logoColor=white)](https://github.com/Snapp-Mobile/ZeplinPersistence/releases)
[![Tests](https://github.com/Snapp-Mobile/ZeplinPersistence/actions/workflows/test.yml/badge.svg)](https://github.com/Snapp-Mobile/ZeplinPersistence/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-22C55E)](LICENSE)

## Overview

ZeplinPersistence is the data layer for the Zeplin Mobile app. It handles storing notifications using CoreData and manages authentication tokens through the iOS keychain. The package uses app groups to share data between the main app and extensions like widgets or notification extensions.

The `PersistenceController` sets up a CoreData stack that can work with shared containers or in-memory stores for testing. The `TokenRepository` is an actor that safely manages OAuth tokens, handling refreshes and waiting for the device to unlock before accessing the keychain.

## Installation

Add ZeplinPersistence to your project using Swift Package Manager. In Xcode, go to File → Add Package Dependencies and enter the repository URL, or add it to your `Package.swift` file.

```swift
dependencies: [
.package(url: "https://github.com/Snapp-Mobile/ZeplinPersistence.git", from: "0.1.0")
]
```

## Usage

Create a persistence controller for your app target. The controller handles setting up the CoreData stack with the appropriate app group identifier.

```swift
import ZeplinPersistence

let persistence = PersistenceController(target: .iOSApp, inMemory: false)
let context = persistence.container.viewContext
```

For testing, use the built-in test controller that creates an in-memory store.

```swift
let testPersistence = PersistenceController.test
```

The token repository manages authentication tokens across your app. Initialize it with your keychain settings and app target.

```swift
let tokenRepo = TokenRepository(
key: "auth-token",
serviceName: "com.snapp.zeplin",
appTarget: .iOSApp,
configuration: apiConfig
)
```

## License

ZeplinPersistence is available under the MIT license. See the LICENSE file for details.
7 changes: 6 additions & 1 deletion Sources/ZeplinPersistence/AppTarget.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//
// AppTarget.swift
//
//
//
// Created by Ilian Konchev on 5.10.21.
//

import Foundation

/// Defines different app targets for sharing data and configuring persistence.
public enum AppTarget: String, CaseIterable, Sendable {
case macOSApp
case macOSWidget
Expand All @@ -16,6 +17,7 @@ public enum AppTarget: String, CaseIterable, Sendable {
case watchOSApp
case watchOSComplication

/// Transaction author identifier for CoreData history tracking.
public var transactionAuthor: String {
switch self {
case .macOSApp:
Expand All @@ -35,6 +37,7 @@ public enum AppTarget: String, CaseIterable, Sendable {
}
}

/// App group identifier for sharing data between targets.
public var groupIdentifier: String {
switch self {
case .macOSApp, .macOSWidget:
Expand All @@ -46,10 +49,12 @@ public enum AppTarget: String, CaseIterable, Sendable {
}
}

/// Shared UserDefaults instance for the app group.
public var userDefaults: UserDefaults? {
return UserDefaults(suiteName: groupIdentifier)
}

/// Widget kind identifier for refreshing widgets.
public var widgetKind: String? {
switch self {
case .macOSApp:
Expand Down
Loading