{"id":29629240,"url":"https://github.com/willswire/store-sentry","last_synced_at":"2025-07-21T09:35:18.052Z","repository":{"id":161333417,"uuid":"636052734","full_name":"willswire/store-sentry","owner":"willswire","description":"Manage access to in-app purchase content hosted in Cloudflare based on App Store Server Notifications","archived":false,"fork":false,"pushed_at":"2023-05-16T14:54:56.000Z","size":19,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-26T03:31:15.031Z","etag":null,"topics":["app-store","app-store-server-api","cloudflare","ios","workers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willswire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-04T03:02:58.000Z","updated_at":"2024-10-31T12:40:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"ffd09a4c-04da-4d2a-94fd-578cedb07670","html_url":"https://github.com/willswire/store-sentry","commit_stats":null,"previous_names":["willswire/store-sentry"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/willswire/store-sentry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willswire%2Fstore-sentry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willswire%2Fstore-sentry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willswire%2Fstore-sentry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willswire%2Fstore-sentry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willswire","download_url":"https://codeload.github.com/willswire/store-sentry/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willswire%2Fstore-sentry/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266276257,"owners_count":23903986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["app-store","app-store-server-api","cloudflare","ios","workers"],"created_at":"2025-07-21T09:35:04.779Z","updated_at":"2025-07-21T09:35:18.047Z","avatar_url":"https://github.com/willswire.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Absolutely, I can help with that. Here's a draft for the README file of your project.\n\n---\n\n# Store-Sentry\n\nStore-Sentry is a serverless application that allows developers to manage access to in-app purchase content hosted on Cloudflare, based on App Store Server Notifications. The application is structured into two main components: `gatekeeper` and `listening-post`.\n\n## Getting Started\n\nBefore setting up Store-Sentry, make sure you have Node.js and npm (Node Package Manager) installed on your machine.\n\n### Prerequisites\n\n- Node.js\n- npm (comes with Node.js)\n- A Cloudflare account\n- Access to the Apple App Store Server Notifications\n\n### Installation\n\n1. Clone the repository\n```bash\ngit clone https://github.com/yourusername/store-sentry.git\n```\n2. Change the directory\n```bash\ncd store-sentry\n```\n3. Install the dependencies\n```bash\nnpm install\n```\n4. Fill out the necessary environment variables in the `wrangler.toml` files in both `gatekeeper` and `listening-post` directories.\n\n## Usage\n\nStore-Sentry is divided into two components:\n\n1. **gatekeeper**: This component is responsible for managing access to in-app purchase content. It controls the access to both public and premium content based on the user status stored in a key-value pair storage.\n\n2. **listening-post**: This component listens for App Store Server Notifications and updates user access status in the key-value pair storage accordingly.\n\nThe two components are independent but work together to manage access to in-app purchase content.\n\n## Contributing\n\n# What this code does:\n\n## Gatekeeper\nThis code defines two functions, `update` and `read`, and exports an object with a `fetch` method. \n\nThe `update` function handles a PUT request. It takes in a `request` object and an `env` object as parameters. It first extracts the search parameters from the request URL and assigns them to `searchParams`. Then, it creates a new URL object from the request URL and assigns it to `url`. It slices the pathname from the URL and assigns it to `fullpath`. It retrieves the value of the \"key\" parameter from `searchParams` and assigns it to `key`.\n\nIf the `key` is equal to the `ADMIN_KEY` stored in the `env` object, it uses the `put` method of `APP_CONTENT` (presumably a storage API) to update the content at the specified `fullpath` with the request body. It returns a response with the message \"Updated {fullpath} successfully!\".\n\nIf the `key` does not match the `ADMIN_KEY`, it returns a response with the message \"Forbidden\" and a status code of 403.\n\nThe `read` function handles a GET request. It takes in a `request` object and an `env` object as parameters. It creates a new URL object from the request URL and assigns it to `url`. It slices the pathname from the URL and assigns it to `fullpath`. It splits the pathname into an array of subpaths using the \"/\" delimiter and assigns it to `subpaths`. \n\nIf the first element of `subpaths` is \"public\", it uses the `get` method of `APP_CONTENT` to retrieve the content at the specified `fullpath` and assigns it to `plan`.\n\nIf the first element of `subpaths` is \"premium\", it retrieves the \"uuid\" parameter from the URL search parameters and assigns it to `uuid`. It uses the `get` method of `APP_USERS` to retrieve the status associated with `uuid` and assigns it to `status`. If `status` is \"ALLOW\", it uses the `get` method of `APP_CONTENT` to retrieve the content at the specified `fullpath` and assigns it to `plan`. If `status` is \"DENY\", it returns a response with the message \"Forbidden\" and a status code of 403.\n\nIf the first element of `subpaths` is neither \"public\" nor \"premium\", it uses the `get` method of `APP_CONTENT` to retrieve the content at the path \"inventory.json\" and assigns it to `plan`.\n\nNext, the function creates a new Headers object and calls the `writeHttpMetadata` method on `plan` (assuming it's an object with that method) to write the HTTP metadata to the headers. It sets the \"etag\" header to the HTTP etag of `plan`. Finally, it returns a response with the body of `plan` and the headers.\n\nThe exported object has a `fetch` method that takes in a `request`, `env`, and `ctx` as parameters. It uses a switch statement to determine the method of the request. If the method is \"PUT\", it calls the `update` function with the `request` and `env` parameters. If the method is \"GET\", it calls the `read` function with the `request` and `env` parameters. Otherwise, it returns a response with the message \"Method Not Allowed\" and a status code of 405.\n\n\n## Listening Post\n\n**This code defines several functions that handle an incoming request and perform various operations based on the request's payload. Here's a breakdown of each function and its purpose:**\n\n1. **read**: This function reads the incoming request body and returns a parsed JSON object if the content-type of the request is \"application/json\". Otherwise, it returns null.\n\n2. **decode**: This function takes a signed payload (assumed to be a JSON web token) and decodes it. It splits the payload by periods, extracts the encoded payload (the second part), and uses the `atob` function to decode the base64-encoded payload. It then parses the decoded payload and returns it as a JSON object.\n\n3. **storeToken**: This function accepts a unique user ID (`uuid`), a notification type, and a subtype. Based on the notification type and subtype, it assigns a verdict (\"ALLOW\" or \"DENY\"). The function stores the `uuid` and the verdict in a KV (Key-Value) database.\n\n4. **handle**: This function is the main request handler. It takes an incoming request as a parameter. If the request method is \"POST\", it reads the request body using the `read` function. If the body contains a \"signedPayload\" property, it decodes the signed payload using the `decode` function and extracts the notification type, subtype, and data from the payload. If the data includes a \"signedTransactionInfo\" property, it decodes it and retrieves the `appAccountToken`. The `storeToken` function is then called with the `appAccountToken`, notification type, and subtype to store the token in the KV database. Finally, it returns a new Response with a status of 202 (Accepted).\n\n5. **addEventListener**: This code registers an event listener for the \"fetch\" event. When a fetch event occurs, it calls the `handle` function with the request and responds with the returned response.\n\nDecodes your JWTs.\n\n\n\n\nPlease read [CONTRIBUTING.md](https://github.com/yourusername/store-sentry/blob/main/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## License\n\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillswire%2Fstore-sentry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillswire%2Fstore-sentry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillswire%2Fstore-sentry/lists"}