@sa2-movie-ticket/contracts 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/README.md +90 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -112,3 +112,93 @@ If you need to generate code locally:
112
112
  # Generate TypeScript and Go
113
113
  bun run generate
114
114
  ```
115
+
116
+ # Details
117
+
118
+ Shared Protobuf contracts and TypeScript definitions for the Movie Ticket microservices.
119
+
120
+ ## Installation
121
+
122
+ You can install this package from **npm** or **GitHub Packages**.
123
+
124
+ ### 1. From Public NPM (Recommended)
125
+
126
+ ```bash
127
+ npm install @sa2-movie-ticket/contracts
128
+ # or
129
+ bun add @sa2-movie-ticket/contracts
130
+ ```
131
+
132
+ ### 2. From GitHub Packages
133
+
134
+ To install from GitHub Packages, you need to configure your `.npmrc` file.
135
+
136
+ **Create/Update `.npmrc`**:
137
+
138
+ ```ini
139
+ @sa2-movie-ticket:registry=https://npm.pkg.github.com
140
+ //npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT
141
+ ```
142
+
143
+ Then install:
144
+
145
+ ```bash
146
+ npm install @sa2-movie-ticket/contracts
147
+ ```
148
+
149
+ ```bash
150
+ bun add @sa2-movie-ticket/contracts
151
+ ```
152
+
153
+ **Note:** This package requires `@grpc/grpc-js` and `@bufbuild/protobuf` as peer dependencies.
154
+
155
+ ```bash
156
+ bun add @grpc/grpc-js @bufbuild/protobuf
157
+ ```
158
+
159
+ ## Structure
160
+
161
+ - `proto/`: Contains the original `.proto` definition files.
162
+ - `gen/ts/`: Contains the generated TypeScript code (by `ts-proto`).
163
+ - `dist/`: Compiled JavaScript output (after `bun run build`).
164
+
165
+ ## scripts
166
+
167
+ - `bun run generate`: Generates TypeScript code from `proto` files.
168
+ - `bun run build`: Compiles the generated TypeScript to JavaScript.
169
+
170
+ ## Usage
171
+
172
+ ### Import generated types
173
+
174
+ ```typescript
175
+ import {
176
+ AuthServiceClient,
177
+ SendOtpRequest,
178
+ } from "@sa2-movie-ticket/contracts/gen/ts/auth";
179
+ import { credentials } from "@grpc/grpc-js";
180
+
181
+ const client = new AuthServiceClient(
182
+ "localhost:50051",
183
+ credentials.createInsecure(),
184
+ );
185
+
186
+ const request = {
187
+ identifier: "test@example.com",
188
+ type: "email",
189
+ };
190
+
191
+ client.SendOtp(request, (err, response) => {
192
+ if (err) {
193
+ console.error(err);
194
+ } else {
195
+ console.log(response);
196
+ }
197
+ });
198
+ ```
199
+
200
+ ## Adding New Contracts
201
+
202
+ 1. Create a new `.proto` file in the `proto/` directory.
203
+ 2. Run `bun run generate` to update the TypeScript definitions.
204
+ 3. Run `bun run build` to compile the package.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sa2-movie-ticket/contracts",
3
3
  "description": "Contracts for movie ticket microservices",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "license": "ISC",
6
6
  "type": "commonjs",
7
7
  "publishConfig": {