Commit Graph
14 Commits
Author SHA1 Message Date
NachoSoto ed80980d08 HTTPClient: verbose logs for request IDs (#3320)
See https://github.com/RevenueCat/khepri/pull/6798.
This can help debug issues as it helps us cross-reference requests on
our end.

### Changes:
- Logging `X-Request-ID` and `X-Amzn-Trace-ID` headers if present (only
in verbose mode)
- Logging these even for failed requests
- Also logging `request_handled_by_load_shedder` for failed requests
- To accomplish that. `HTTPURLResponse` now conforms to our
`HTTPResponseType`, this allows us to extract headers in an uniform way

### Example:
```
[network] DEBUG: ℹ️ API request completed: GET '/v1/subscribers/$RCAnonymousID%3Ad9dc4f3b33054cf28c0f2ec9da0f48d5' (304)
Request-ID: 'be534c50-5231-403b-be2f-7c077861751d'; Amzn-Trace-ID: 'Root=1-6532c6ca-7ef80f961ec9c4145484df13'
```
2023-10-25 20:24:23 -07:00
NachoSoto 7f875ae212 Changed Logger to use os_log (#2608) 2023-06-15 15:13:48 -07:00
NachoSoto 64c8638425 Create separate SPM library to enable custom entitlement computation (#2440)
Fixes SDK-3084

![screenshot_2023-04-25_at_10 02
44_480](https://user-images.githubusercontent.com/685609/234360670-bd2628a1-0684-490d-a9eb-33846a60f72a.png)

## Changes:

- Added new `ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION` compile time flag
- Hidden `configureInCustomEntitlementsModeWithApiKey` behind
`ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION`
- Added new `RevenueCat_CustomEntitlementComputation` SPM target and
library
- Added CircleCI job for `swift build --target
RevenueCat_CustomEntitlementComputation`
- Added new `SPMCustomEntitlementComputationInstallation` using the new
`configureInCustomEntitlementsComputationMode`
- Added CircleCI job for `SPMCustomEntitlementComputationInstallation`
- Added `FrameworkDisambiguation.swift` to avoid using `RevenueCat.`
disambiguation for files that
- Changed API testers to only use the new methods if
`ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION` is defined
- Updated `DangerousSettings` to not expose
`customEntitlementComputation` publicly. The only way to use that now
with `public` API is through
`Purchases.configureInCustomEntitlementsModeWithApiKey`
- Updated sample app to use new library
2023-04-25 15:11:58 -07:00
NachoSoto b3875a9380 Exposed PurchasesReceiptParser and AppleReceipt (#2153)
Initial step for [CSDK-17]. Fixes [CSDK-523].

### Changes:
- Renamed `ReceiptParser` to `PurchasesReceiptParser` to avoid name
collision with future SPM `ReceiptParser`
- Exposed `ReceiptParser`, `AppleReceipt`,
`PurchasesReceiptParser.Error`
- Added new types to `SwiftAPITester`
- Added docs to these types
- Moved `LoggerType` to be available to `ReceiptParser`
- Moved `DateFormatter+Extensions` to be available to `ReceiptParser`
- Moved `Codable+Extensions` to be available to `ReceiptParser`
- Created `ReceiptParserLogger` for `ReceiptParser`


[CSDK-17]:
https://revenuecats.atlassian.net/browse/CSDK-17?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

[CSDK-523]:
https://revenuecats.atlassian.net/browse/CSDK-523?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-12-22 10:09:12 -08:00
NachoSoto 1030cf2517 Extracted LoggerType (#2098) 2022-12-07 15:06:37 -08:00
NachoSoto 872b4cf566 Fixed LogLevel ordering and added tests (#2102) 2022-11-30 06:17:12 -08:00
NachoSoto b91a0ecf2f StoreKit: added logs when purchasing and product requests are too slow (#2061)
Using #2059 in a few places for now.
We can add this to more places, and tweak the thresholds.

Fixes [CSDK-512].

[CSDK-512]:
https://revenuecats.atlassian.net/browse/CSDK-512?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-11-25 17:00:54 -08:00
NachoSoto f610524ae3 Added LogLevel.verbose (#2080)
I want to add some extra logs to figure out [CSDK-517] which would be
too verbose (no pun intended) for `debug`, so this will allow us to have
some additional logging that wouldn't be enabled by default.

[CSDK-517]:
https://revenuecats.atlassian.net/browse/CSDK-517?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-11-25 16:56:17 -08:00
NachoSoto 4340f75385 Logger: exposed generic log method (#2058)
This will be used for [CSDK-512] to be able to configure the log level.

[CSDK-512]:
https://revenuecats.atlassian.net/browse/CSDK-512?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-11-23 11:51:35 -06:00
NachoSoto 4fffe831cc Logger: refactored default LogLevel definition (#1934)
Defining the property "twice" was a big weird and hard to read. Now
`logLevel` is only defined once, with the default value extracted into a
separate method.
2022-09-23 11:40:39 -07:00
NachoSoto 58e15c88ad Introduced TestLogHandler to simplify how we test logged messages (#1858)
We had this fragile pattern in several tests:
```swift
var loggedMessages = [String]()
let originalLogHandler = Logger.logHandler
defer { Logger.logHandler = originalLogHandler }

Logger.logHandler = { _, message, _, _, _ in
    loggedMessages.append(message)
}
```

Which was too verbose and error prone.

This new type works like an RAII type. Its lifetime scopes the messages that are observed, so simply having a reference around for the lifetime of the test allows observing only those messages.

This much simpler abstraction will make it easier for us to test more of what's logged by the SDK.

### Examples:

- Initialize in `setUp`:

```swift
private var testLogHandler: TestLogHandler!
override func setUp() {
    super.setUp()
    self.testLogHandler = TestLogHandler()
}
override func tearDown() {
    self.testLogHandler = nil
    super.tearDown()
}

func testExample() {
    // Run code

    expect(self.testLogHandler.messages).to(contain(...))
}
```

 - Alternatively, `TestLogHandler` can be used locally within a single test:

```swift
func testExample() {
    let logHandler = TestLogHandler()

    // Run some code

    expect(logHandler.loggedMessages.onlyElement?.message) == "Expected log"
}
```

### Notes:

This implicitly overrides `Purchases.shared.verboseLogHandler` while running tests, but it just wraps it by still invoking the default handler, so logs are still printed in the console.
2022-08-31 10:07:52 -07:00
NachoSoto a95fb58f28 Logger: wrap message in @autoclosure to avoid creating when LogLevel is disabled (#1781)
I realized in #1780 that we might be doing unnecessary work creating messages that are never logged. This is a small optimization to prevent that.
2022-07-29 13:19:34 -07:00
NachoSoto f1044bce14 PurchasesOrchestrator: added logs for completed and failed purchases (#1493)
Follow up to #1489

Examples:
> 2022-04-11 14:36:08.815265-0700 UnitTestsHostApp[58688:3901390] [Purchases] - INFO: 😻💰 Purchased product - 'com.revenuecat.monthly_4.99.1_week_intro'
> 2022-04-11 14:37:31.793204-0700 BackendIntegrationTestsHostApp[58835:3904176] [Purchases] - ERROR: 💰 Product purchase for 'com.revenuecat.monthly_4.99.1_week_intro' failed with error: Error Domain=RevenueCat.ErrorCode Code=34 "The information associated with this PromotionalOffer is not valid.
2022-04-12 09:42:17 -07:00
aboedo f5697de730 renamed Purchases folder to Sources (#1416)
* renamed `Purchases` folder to `Sources`

* temporarily enabling installation test jobs

* re-disabling installation test jobs
2022-03-28 11:53:24 -03:00