|
| 1 | +# @swipecast/shared |
| 2 | + |
| 3 | +Shared business logic package for Swipecast React Native and Web applications. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @swipecast/shared |
| 9 | +# or |
| 10 | +yarn add @swipecast/shared |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### StripeHelpers |
| 16 | + |
| 17 | +```typescript |
| 18 | +import { StripeHelpers } from '@swipecast/shared'; |
| 19 | + |
| 20 | +const card = { |
| 21 | + brand: 'American Express', |
| 22 | + last4: '1234', |
| 23 | + exp_month: 12, |
| 24 | + exp_year: 2025, |
| 25 | +}; |
| 26 | + |
| 27 | +const label = StripeHelpers.getCardBrandLabel(card); // "Amex" |
| 28 | +``` |
| 29 | + |
| 30 | +## Development |
| 31 | + |
| 32 | +### Setup |
| 33 | + |
| 34 | +```bash |
| 35 | +npm install |
| 36 | +``` |
| 37 | + |
| 38 | +### Build |
| 39 | + |
| 40 | +```bash |
| 41 | +npm run build |
| 42 | +``` |
| 43 | + |
| 44 | +This will compile TypeScript to JavaScript in the `dist` directory. |
| 45 | + |
| 46 | +## Publishing |
| 47 | + |
| 48 | +### Automatic Publishing (CI/CD) |
| 49 | + |
| 50 | +The package is automatically published to npm when code is pushed to the `main` branch. The workflow will: |
| 51 | +1. Build the package |
| 52 | +2. Publish to npm using the `NPM_TOKEN` secret |
| 53 | + |
| 54 | +**Setup:** |
| 55 | +1. Add your npm token as a GitHub secret named `NPM_TOKEN`: |
| 56 | + - Go to your repository settings → Secrets and variables → Actions |
| 57 | + - Add a new secret with your npm token (get it from npmjs.com → Access Tokens) |
| 58 | + |
| 59 | +2. Update the version in `package.json` before pushing: |
| 60 | + ```bash |
| 61 | + npm version patch # for bug fixes |
| 62 | + npm version minor # for new features |
| 63 | + npm version major # for breaking changes |
| 64 | + ``` |
| 65 | + |
| 66 | +3. Push to main: |
| 67 | + ```bash |
| 68 | + git push origin main |
| 69 | + ``` |
| 70 | + |
| 71 | +**Skip publishing:** Add `[skip publish]` to your commit message to skip automatic publishing. |
| 72 | + |
| 73 | +### Manual Publishing |
| 74 | + |
| 75 | +If you need to publish manually: |
| 76 | + |
| 77 | +1. Make sure you're logged into npm: |
| 78 | + ```bash |
| 79 | + npm login |
| 80 | + ``` |
| 81 | + |
| 82 | +2. Update the version in `package.json`: |
| 83 | + ```bash |
| 84 | + npm version patch # for bug fixes |
| 85 | + npm version minor # for new features |
| 86 | + npm version major # for breaking changes |
| 87 | + ``` |
| 88 | + |
| 89 | +3. Publish: |
| 90 | + ```bash |
| 91 | + npm publish |
| 92 | + ``` |
| 93 | + |
| 94 | +The `prepublishOnly` script will automatically build the package before publishing. |
| 95 | + |
| 96 | +### Publishing to a Private Registry |
| 97 | + |
| 98 | +If you're using a private npm registry, update the `publishConfig` in `package.json`: |
| 99 | + |
| 100 | +```json |
| 101 | +{ |
| 102 | + "publishConfig": { |
| 103 | + "registry": "https://your-private-registry.com" |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +## Project Structure |
| 109 | + |
| 110 | +``` |
| 111 | +shared/ |
| 112 | +├── src/ |
| 113 | +│ ├── stripe_helpers.ts # Stripe-related business logic |
| 114 | +│ └── index.ts # Main entry point |
| 115 | +├── dist/ # Compiled output (generated) |
| 116 | +├── package.json |
| 117 | +├── tsconfig.json |
| 118 | +└── README.md |
| 119 | +``` |
| 120 | + |
| 121 | +## License |
| 122 | + |
| 123 | +UNLICENSED |
0 commit comments