@sagebox-be/proto-contracts 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # @sagebox-be/proto-contracts
2
+
3
+ Sagebox gRPC Protocol Buffer contracts and TypeScript type definitions.
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @sagebox-be/proto-contracts
9
+ # or
10
+ yarn add @sagebox-be/proto-contracts
11
+ # or
12
+ pnpm add @sagebox-be/proto-contracts
13
+ ```
14
+
15
+ ## 🚀 Usage
16
+
17
+ ### Import TypeScript Types
18
+
19
+ ```typescript
20
+ import {
21
+ ProductServiceClient,
22
+ ProductServiceController,
23
+ GetProductByIdRequest,
24
+ ProductResponse,
25
+ getProtoPath,
26
+ getAllProtosPaths,
27
+ } from '@sagebox-be/proto-contracts';
28
+ ```
29
+
30
+ ### Use in NestJS gRPC Microservice
31
+
32
+ ```typescript
33
+ import { Module } from '@nestjs/common';
34
+ import { Transport, ClientsModule } from '@nestjs/microservices';
35
+ import { getProtoPath } from '@sagebox-be/proto-contracts';
36
+
37
+ @Module({
38
+ imports: [
39
+ ClientsModule.register([
40
+ {
41
+ name: 'PRODUCT_SERVICE',
42
+ transport: Transport.GRPC,
43
+ options: {
44
+ package: 'product',
45
+ protoPath: getProtoPath('product.proto'),
46
+ url: 'localhost:5000',
47
+ },
48
+ },
49
+ ]),
50
+ ],
51
+ })
52
+ export class AppModule {}
53
+ ```
54
+
55
+ ### Use in Node.js gRPC Client
56
+
57
+ ```typescript
58
+ import * as grpc from '@grpc/grpc-js';
59
+ import * as protoLoader from '@grpc/proto-loader';
60
+ import { getProtoPath } from '@sagebox-be/proto-contracts';
61
+ import type { ProductServiceClient } from '@sagebox-be/proto-contracts';
62
+
63
+ const PROTO_PATH = getProtoPath('product.proto');
64
+
65
+ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
66
+ keepCase: true,
67
+ longs: String,
68
+ enums: String,
69
+ defaults: true,
70
+ oneofs: true,
71
+ });
72
+
73
+ const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
74
+ const productProto = protoDescriptor.product as any;
75
+
76
+ const client: ProductServiceClient = new productProto.ProductService(
77
+ 'localhost:5000',
78
+ grpc.credentials.createInsecure()
79
+ );
80
+
81
+ // Make gRPC calls
82
+ client.getProductById({ id: 'product-123' }, (error, response) => {
83
+ if (error) {
84
+ console.error(error);
85
+ } else {
86
+ console.log(response);
87
+ }
88
+ });
89
+ ```
90
+
91
+ ### Use Proto Files Directly
92
+
93
+ ```typescript
94
+ import { getAllProtosPaths } from '@sagebox-be/proto-contracts';
95
+
96
+ const protoPaths = getAllProtosPaths();
97
+ console.log(protoPaths.product); // Path to product.proto
98
+ ```
99
+
100
+ ## 📁 Package Contents
101
+
102
+ - **TypeScript Types**: Generated from proto files with full type safety
103
+ - **Proto Files**: Original `.proto` files for gRPC code generation in any language
104
+ - **Helper Functions**: Utilities to get proto file paths
105
+
106
+ ## 🔧 Development
107
+
108
+ ### Generate Types from Proto
109
+
110
+ ```bash
111
+ npm run proto:generate
112
+ ```
113
+
114
+ ### Build Package
115
+
116
+ ```bash
117
+ npm run build
118
+ ```
119
+
120
+ ### Publish
121
+
122
+ ```bash
123
+ npm publish
124
+ ```
125
+
126
+ ## 📖 Available Services
127
+
128
+ ### ProductService
129
+
130
+ #### Methods
131
+
132
+ - `GetProductsByCategoryId(GetProductsByCategoryIdRequest): GetProductsResponse`
133
+ - `GetProductById(GetProductByIdRequest): ProductResponse`
134
+ - `CreateProduct(CreateProductRequest): ProductResponse`
135
+
136
+ ## 🤝 Contributing
137
+
138
+ When adding new proto files:
139
+
140
+ 1. Add the `.proto` file to `proto/` directory
141
+ 2. Run `npm run proto:generate` to generate TypeScript types
142
+ 3. Export types in `src/index.ts`
143
+ 4. Update `getAllProtosPaths()` in `src/utils.ts`
144
+ 5. Build and publish
145
+
146
+ ## 📝 License
147
+
148
+ MIT
@@ -0,0 +1,2 @@
1
+ export * from './interfaces/product';
2
+ export { getProtoPath } from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getProtoPath = void 0;
18
+ // Export all gRPC interfaces and types
19
+ __exportStar(require("./interfaces/product"), exports);
20
+ // Export proto file path helper
21
+ var utils_1 = require("./utils");
22
+ Object.defineProperty(exports, "getProtoPath", { enumerable: true, get: function () { return utils_1.getProtoPath; } });
@@ -0,0 +1,91 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ import type { Metadata } from "@grpc/grpc-js";
3
+ import { Observable } from "rxjs";
4
+ export declare const protobufPackage = "product";
5
+ /** Request messages */
6
+ export interface GetProductsByCategoryIdRequest {
7
+ categoryId: string;
8
+ }
9
+ export interface GetProductByIdRequest {
10
+ id: string;
11
+ }
12
+ export interface CreateProductRequest {
13
+ name: string;
14
+ title: string;
15
+ description: string;
16
+ categoryId: string;
17
+ storeId: string;
18
+ status: string;
19
+ mediaKeys: string[];
20
+ skus: ProductSkuInput[];
21
+ }
22
+ /** Response messages */
23
+ export interface GetProductsResponse {
24
+ products: Product[];
25
+ }
26
+ export interface ProductResponse {
27
+ product: Product | undefined;
28
+ error: string;
29
+ }
30
+ /** Data structures */
31
+ export interface Product {
32
+ id: string;
33
+ name: string;
34
+ title: string;
35
+ description: string;
36
+ keywords: string;
37
+ categoryId: string;
38
+ storeId: string;
39
+ viewedCount: number;
40
+ status: string;
41
+ url: string;
42
+ media: Media[];
43
+ createdAt: string;
44
+ updatedAt: string;
45
+ }
46
+ export interface Media {
47
+ id: string;
48
+ key: string;
49
+ url: string;
50
+ type: string;
51
+ createdAt: string;
52
+ updatedAt: string;
53
+ }
54
+ export interface ProductSkuInput {
55
+ price: number;
56
+ quantity: number;
57
+ brand?: string | undefined;
58
+ mediaKeys: string[];
59
+ attributeValues: AttributeValueInput[];
60
+ }
61
+ export interface AttributeValueInput {
62
+ attrId: string;
63
+ value: string;
64
+ name: string;
65
+ }
66
+ export declare const PRODUCT_PACKAGE_NAME = "product";
67
+ export declare const GetProductsByCategoryIdRequest: MessageFns<GetProductsByCategoryIdRequest>;
68
+ export declare const GetProductByIdRequest: MessageFns<GetProductByIdRequest>;
69
+ export declare const CreateProductRequest: MessageFns<CreateProductRequest>;
70
+ export declare const GetProductsResponse: MessageFns<GetProductsResponse>;
71
+ export declare const ProductResponse: MessageFns<ProductResponse>;
72
+ export declare const Product: MessageFns<Product>;
73
+ export declare const Media: MessageFns<Media>;
74
+ export declare const ProductSkuInput: MessageFns<ProductSkuInput>;
75
+ export declare const AttributeValueInput: MessageFns<AttributeValueInput>;
76
+ export interface ProductServiceClient {
77
+ getProductsByCategoryId(request: GetProductsByCategoryIdRequest, metadata?: Metadata): Observable<GetProductsResponse>;
78
+ getProductById(request: GetProductByIdRequest, metadata?: Metadata): Observable<ProductResponse>;
79
+ createProduct(request: CreateProductRequest, metadata?: Metadata): Observable<ProductResponse>;
80
+ }
81
+ export interface ProductServiceController {
82
+ getProductsByCategoryId(request: GetProductsByCategoryIdRequest, metadata?: Metadata): Promise<GetProductsResponse> | Observable<GetProductsResponse> | GetProductsResponse;
83
+ getProductById(request: GetProductByIdRequest, metadata?: Metadata): Promise<ProductResponse> | Observable<ProductResponse> | ProductResponse;
84
+ createProduct(request: CreateProductRequest, metadata?: Metadata): Promise<ProductResponse> | Observable<ProductResponse> | ProductResponse;
85
+ }
86
+ export declare function ProductServiceControllerMethods(): (constructor: Function) => void;
87
+ export declare const PRODUCT_SERVICE_NAME = "ProductService";
88
+ export interface MessageFns<T> {
89
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
90
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
91
+ }
@@ -0,0 +1,650 @@
1
+ "use strict";
2
+ // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
+ // versions:
4
+ // protoc-gen-ts_proto v2.8.3
5
+ // protoc v6.33.2
6
+ // source: product.proto
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.PRODUCT_SERVICE_NAME = exports.AttributeValueInput = exports.ProductSkuInput = exports.Media = exports.Product = exports.ProductResponse = exports.GetProductsResponse = exports.CreateProductRequest = exports.GetProductByIdRequest = exports.GetProductsByCategoryIdRequest = exports.PRODUCT_PACKAGE_NAME = exports.protobufPackage = void 0;
9
+ exports.ProductServiceControllerMethods = ProductServiceControllerMethods;
10
+ /* eslint-disable */
11
+ const wire_1 = require("@bufbuild/protobuf/wire");
12
+ const microservices_1 = require("@nestjs/microservices");
13
+ exports.protobufPackage = "product";
14
+ exports.PRODUCT_PACKAGE_NAME = "product";
15
+ function createBaseGetProductsByCategoryIdRequest() {
16
+ return { categoryId: "" };
17
+ }
18
+ exports.GetProductsByCategoryIdRequest = {
19
+ encode(message, writer = new wire_1.BinaryWriter()) {
20
+ if (message.categoryId !== "") {
21
+ writer.uint32(10).string(message.categoryId);
22
+ }
23
+ return writer;
24
+ },
25
+ decode(input, length) {
26
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
27
+ const end = length === undefined ? reader.len : reader.pos + length;
28
+ const message = createBaseGetProductsByCategoryIdRequest();
29
+ while (reader.pos < end) {
30
+ const tag = reader.uint32();
31
+ switch (tag >>> 3) {
32
+ case 1: {
33
+ if (tag !== 10) {
34
+ break;
35
+ }
36
+ message.categoryId = reader.string();
37
+ continue;
38
+ }
39
+ }
40
+ if ((tag & 7) === 4 || tag === 0) {
41
+ break;
42
+ }
43
+ reader.skip(tag & 7);
44
+ }
45
+ return message;
46
+ },
47
+ };
48
+ function createBaseGetProductByIdRequest() {
49
+ return { id: "" };
50
+ }
51
+ exports.GetProductByIdRequest = {
52
+ encode(message, writer = new wire_1.BinaryWriter()) {
53
+ if (message.id !== "") {
54
+ writer.uint32(10).string(message.id);
55
+ }
56
+ return writer;
57
+ },
58
+ decode(input, length) {
59
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
60
+ const end = length === undefined ? reader.len : reader.pos + length;
61
+ const message = createBaseGetProductByIdRequest();
62
+ while (reader.pos < end) {
63
+ const tag = reader.uint32();
64
+ switch (tag >>> 3) {
65
+ case 1: {
66
+ if (tag !== 10) {
67
+ break;
68
+ }
69
+ message.id = reader.string();
70
+ continue;
71
+ }
72
+ }
73
+ if ((tag & 7) === 4 || tag === 0) {
74
+ break;
75
+ }
76
+ reader.skip(tag & 7);
77
+ }
78
+ return message;
79
+ },
80
+ };
81
+ function createBaseCreateProductRequest() {
82
+ return { name: "", title: "", description: "", categoryId: "", storeId: "", status: "", mediaKeys: [], skus: [] };
83
+ }
84
+ exports.CreateProductRequest = {
85
+ encode(message, writer = new wire_1.BinaryWriter()) {
86
+ if (message.name !== "") {
87
+ writer.uint32(10).string(message.name);
88
+ }
89
+ if (message.title !== "") {
90
+ writer.uint32(18).string(message.title);
91
+ }
92
+ if (message.description !== "") {
93
+ writer.uint32(26).string(message.description);
94
+ }
95
+ if (message.categoryId !== "") {
96
+ writer.uint32(34).string(message.categoryId);
97
+ }
98
+ if (message.storeId !== "") {
99
+ writer.uint32(42).string(message.storeId);
100
+ }
101
+ if (message.status !== "") {
102
+ writer.uint32(50).string(message.status);
103
+ }
104
+ for (const v of message.mediaKeys) {
105
+ writer.uint32(58).string(v);
106
+ }
107
+ for (const v of message.skus) {
108
+ exports.ProductSkuInput.encode(v, writer.uint32(66).fork()).join();
109
+ }
110
+ return writer;
111
+ },
112
+ decode(input, length) {
113
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
114
+ const end = length === undefined ? reader.len : reader.pos + length;
115
+ const message = createBaseCreateProductRequest();
116
+ while (reader.pos < end) {
117
+ const tag = reader.uint32();
118
+ switch (tag >>> 3) {
119
+ case 1: {
120
+ if (tag !== 10) {
121
+ break;
122
+ }
123
+ message.name = reader.string();
124
+ continue;
125
+ }
126
+ case 2: {
127
+ if (tag !== 18) {
128
+ break;
129
+ }
130
+ message.title = reader.string();
131
+ continue;
132
+ }
133
+ case 3: {
134
+ if (tag !== 26) {
135
+ break;
136
+ }
137
+ message.description = reader.string();
138
+ continue;
139
+ }
140
+ case 4: {
141
+ if (tag !== 34) {
142
+ break;
143
+ }
144
+ message.categoryId = reader.string();
145
+ continue;
146
+ }
147
+ case 5: {
148
+ if (tag !== 42) {
149
+ break;
150
+ }
151
+ message.storeId = reader.string();
152
+ continue;
153
+ }
154
+ case 6: {
155
+ if (tag !== 50) {
156
+ break;
157
+ }
158
+ message.status = reader.string();
159
+ continue;
160
+ }
161
+ case 7: {
162
+ if (tag !== 58) {
163
+ break;
164
+ }
165
+ message.mediaKeys.push(reader.string());
166
+ continue;
167
+ }
168
+ case 8: {
169
+ if (tag !== 66) {
170
+ break;
171
+ }
172
+ message.skus.push(exports.ProductSkuInput.decode(reader, reader.uint32()));
173
+ continue;
174
+ }
175
+ }
176
+ if ((tag & 7) === 4 || tag === 0) {
177
+ break;
178
+ }
179
+ reader.skip(tag & 7);
180
+ }
181
+ return message;
182
+ },
183
+ };
184
+ function createBaseGetProductsResponse() {
185
+ return { products: [] };
186
+ }
187
+ exports.GetProductsResponse = {
188
+ encode(message, writer = new wire_1.BinaryWriter()) {
189
+ for (const v of message.products) {
190
+ exports.Product.encode(v, writer.uint32(10).fork()).join();
191
+ }
192
+ return writer;
193
+ },
194
+ decode(input, length) {
195
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
196
+ const end = length === undefined ? reader.len : reader.pos + length;
197
+ const message = createBaseGetProductsResponse();
198
+ while (reader.pos < end) {
199
+ const tag = reader.uint32();
200
+ switch (tag >>> 3) {
201
+ case 1: {
202
+ if (tag !== 10) {
203
+ break;
204
+ }
205
+ message.products.push(exports.Product.decode(reader, reader.uint32()));
206
+ continue;
207
+ }
208
+ }
209
+ if ((tag & 7) === 4 || tag === 0) {
210
+ break;
211
+ }
212
+ reader.skip(tag & 7);
213
+ }
214
+ return message;
215
+ },
216
+ };
217
+ function createBaseProductResponse() {
218
+ return { product: undefined, error: "" };
219
+ }
220
+ exports.ProductResponse = {
221
+ encode(message, writer = new wire_1.BinaryWriter()) {
222
+ if (message.product !== undefined) {
223
+ exports.Product.encode(message.product, writer.uint32(10).fork()).join();
224
+ }
225
+ if (message.error !== "") {
226
+ writer.uint32(18).string(message.error);
227
+ }
228
+ return writer;
229
+ },
230
+ decode(input, length) {
231
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
232
+ const end = length === undefined ? reader.len : reader.pos + length;
233
+ const message = createBaseProductResponse();
234
+ while (reader.pos < end) {
235
+ const tag = reader.uint32();
236
+ switch (tag >>> 3) {
237
+ case 1: {
238
+ if (tag !== 10) {
239
+ break;
240
+ }
241
+ message.product = exports.Product.decode(reader, reader.uint32());
242
+ continue;
243
+ }
244
+ case 2: {
245
+ if (tag !== 18) {
246
+ break;
247
+ }
248
+ message.error = reader.string();
249
+ continue;
250
+ }
251
+ }
252
+ if ((tag & 7) === 4 || tag === 0) {
253
+ break;
254
+ }
255
+ reader.skip(tag & 7);
256
+ }
257
+ return message;
258
+ },
259
+ };
260
+ function createBaseProduct() {
261
+ return {
262
+ id: "",
263
+ name: "",
264
+ title: "",
265
+ description: "",
266
+ keywords: "",
267
+ categoryId: "",
268
+ storeId: "",
269
+ viewedCount: 0,
270
+ status: "",
271
+ url: "",
272
+ media: [],
273
+ createdAt: "",
274
+ updatedAt: "",
275
+ };
276
+ }
277
+ exports.Product = {
278
+ encode(message, writer = new wire_1.BinaryWriter()) {
279
+ if (message.id !== "") {
280
+ writer.uint32(10).string(message.id);
281
+ }
282
+ if (message.name !== "") {
283
+ writer.uint32(18).string(message.name);
284
+ }
285
+ if (message.title !== "") {
286
+ writer.uint32(26).string(message.title);
287
+ }
288
+ if (message.description !== "") {
289
+ writer.uint32(34).string(message.description);
290
+ }
291
+ if (message.keywords !== "") {
292
+ writer.uint32(42).string(message.keywords);
293
+ }
294
+ if (message.categoryId !== "") {
295
+ writer.uint32(50).string(message.categoryId);
296
+ }
297
+ if (message.storeId !== "") {
298
+ writer.uint32(58).string(message.storeId);
299
+ }
300
+ if (message.viewedCount !== 0) {
301
+ writer.uint32(64).int32(message.viewedCount);
302
+ }
303
+ if (message.status !== "") {
304
+ writer.uint32(74).string(message.status);
305
+ }
306
+ if (message.url !== "") {
307
+ writer.uint32(82).string(message.url);
308
+ }
309
+ for (const v of message.media) {
310
+ exports.Media.encode(v, writer.uint32(90).fork()).join();
311
+ }
312
+ if (message.createdAt !== "") {
313
+ writer.uint32(98).string(message.createdAt);
314
+ }
315
+ if (message.updatedAt !== "") {
316
+ writer.uint32(106).string(message.updatedAt);
317
+ }
318
+ return writer;
319
+ },
320
+ decode(input, length) {
321
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
322
+ const end = length === undefined ? reader.len : reader.pos + length;
323
+ const message = createBaseProduct();
324
+ while (reader.pos < end) {
325
+ const tag = reader.uint32();
326
+ switch (tag >>> 3) {
327
+ case 1: {
328
+ if (tag !== 10) {
329
+ break;
330
+ }
331
+ message.id = reader.string();
332
+ continue;
333
+ }
334
+ case 2: {
335
+ if (tag !== 18) {
336
+ break;
337
+ }
338
+ message.name = reader.string();
339
+ continue;
340
+ }
341
+ case 3: {
342
+ if (tag !== 26) {
343
+ break;
344
+ }
345
+ message.title = reader.string();
346
+ continue;
347
+ }
348
+ case 4: {
349
+ if (tag !== 34) {
350
+ break;
351
+ }
352
+ message.description = reader.string();
353
+ continue;
354
+ }
355
+ case 5: {
356
+ if (tag !== 42) {
357
+ break;
358
+ }
359
+ message.keywords = reader.string();
360
+ continue;
361
+ }
362
+ case 6: {
363
+ if (tag !== 50) {
364
+ break;
365
+ }
366
+ message.categoryId = reader.string();
367
+ continue;
368
+ }
369
+ case 7: {
370
+ if (tag !== 58) {
371
+ break;
372
+ }
373
+ message.storeId = reader.string();
374
+ continue;
375
+ }
376
+ case 8: {
377
+ if (tag !== 64) {
378
+ break;
379
+ }
380
+ message.viewedCount = reader.int32();
381
+ continue;
382
+ }
383
+ case 9: {
384
+ if (tag !== 74) {
385
+ break;
386
+ }
387
+ message.status = reader.string();
388
+ continue;
389
+ }
390
+ case 10: {
391
+ if (tag !== 82) {
392
+ break;
393
+ }
394
+ message.url = reader.string();
395
+ continue;
396
+ }
397
+ case 11: {
398
+ if (tag !== 90) {
399
+ break;
400
+ }
401
+ message.media.push(exports.Media.decode(reader, reader.uint32()));
402
+ continue;
403
+ }
404
+ case 12: {
405
+ if (tag !== 98) {
406
+ break;
407
+ }
408
+ message.createdAt = reader.string();
409
+ continue;
410
+ }
411
+ case 13: {
412
+ if (tag !== 106) {
413
+ break;
414
+ }
415
+ message.updatedAt = reader.string();
416
+ continue;
417
+ }
418
+ }
419
+ if ((tag & 7) === 4 || tag === 0) {
420
+ break;
421
+ }
422
+ reader.skip(tag & 7);
423
+ }
424
+ return message;
425
+ },
426
+ };
427
+ function createBaseMedia() {
428
+ return { id: "", key: "", url: "", type: "", createdAt: "", updatedAt: "" };
429
+ }
430
+ exports.Media = {
431
+ encode(message, writer = new wire_1.BinaryWriter()) {
432
+ if (message.id !== "") {
433
+ writer.uint32(10).string(message.id);
434
+ }
435
+ if (message.key !== "") {
436
+ writer.uint32(18).string(message.key);
437
+ }
438
+ if (message.url !== "") {
439
+ writer.uint32(26).string(message.url);
440
+ }
441
+ if (message.type !== "") {
442
+ writer.uint32(34).string(message.type);
443
+ }
444
+ if (message.createdAt !== "") {
445
+ writer.uint32(42).string(message.createdAt);
446
+ }
447
+ if (message.updatedAt !== "") {
448
+ writer.uint32(50).string(message.updatedAt);
449
+ }
450
+ return writer;
451
+ },
452
+ decode(input, length) {
453
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
454
+ const end = length === undefined ? reader.len : reader.pos + length;
455
+ const message = createBaseMedia();
456
+ while (reader.pos < end) {
457
+ const tag = reader.uint32();
458
+ switch (tag >>> 3) {
459
+ case 1: {
460
+ if (tag !== 10) {
461
+ break;
462
+ }
463
+ message.id = reader.string();
464
+ continue;
465
+ }
466
+ case 2: {
467
+ if (tag !== 18) {
468
+ break;
469
+ }
470
+ message.key = reader.string();
471
+ continue;
472
+ }
473
+ case 3: {
474
+ if (tag !== 26) {
475
+ break;
476
+ }
477
+ message.url = reader.string();
478
+ continue;
479
+ }
480
+ case 4: {
481
+ if (tag !== 34) {
482
+ break;
483
+ }
484
+ message.type = reader.string();
485
+ continue;
486
+ }
487
+ case 5: {
488
+ if (tag !== 42) {
489
+ break;
490
+ }
491
+ message.createdAt = reader.string();
492
+ continue;
493
+ }
494
+ case 6: {
495
+ if (tag !== 50) {
496
+ break;
497
+ }
498
+ message.updatedAt = reader.string();
499
+ continue;
500
+ }
501
+ }
502
+ if ((tag & 7) === 4 || tag === 0) {
503
+ break;
504
+ }
505
+ reader.skip(tag & 7);
506
+ }
507
+ return message;
508
+ },
509
+ };
510
+ function createBaseProductSkuInput() {
511
+ return { price: 0, quantity: 0, mediaKeys: [], attributeValues: [] };
512
+ }
513
+ exports.ProductSkuInput = {
514
+ encode(message, writer = new wire_1.BinaryWriter()) {
515
+ if (message.price !== 0) {
516
+ writer.uint32(8).int32(message.price);
517
+ }
518
+ if (message.quantity !== 0) {
519
+ writer.uint32(16).int32(message.quantity);
520
+ }
521
+ if (message.brand !== undefined) {
522
+ writer.uint32(26).string(message.brand);
523
+ }
524
+ for (const v of message.mediaKeys) {
525
+ writer.uint32(34).string(v);
526
+ }
527
+ for (const v of message.attributeValues) {
528
+ exports.AttributeValueInput.encode(v, writer.uint32(42).fork()).join();
529
+ }
530
+ return writer;
531
+ },
532
+ decode(input, length) {
533
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
534
+ const end = length === undefined ? reader.len : reader.pos + length;
535
+ const message = createBaseProductSkuInput();
536
+ while (reader.pos < end) {
537
+ const tag = reader.uint32();
538
+ switch (tag >>> 3) {
539
+ case 1: {
540
+ if (tag !== 8) {
541
+ break;
542
+ }
543
+ message.price = reader.int32();
544
+ continue;
545
+ }
546
+ case 2: {
547
+ if (tag !== 16) {
548
+ break;
549
+ }
550
+ message.quantity = reader.int32();
551
+ continue;
552
+ }
553
+ case 3: {
554
+ if (tag !== 26) {
555
+ break;
556
+ }
557
+ message.brand = reader.string();
558
+ continue;
559
+ }
560
+ case 4: {
561
+ if (tag !== 34) {
562
+ break;
563
+ }
564
+ message.mediaKeys.push(reader.string());
565
+ continue;
566
+ }
567
+ case 5: {
568
+ if (tag !== 42) {
569
+ break;
570
+ }
571
+ message.attributeValues.push(exports.AttributeValueInput.decode(reader, reader.uint32()));
572
+ continue;
573
+ }
574
+ }
575
+ if ((tag & 7) === 4 || tag === 0) {
576
+ break;
577
+ }
578
+ reader.skip(tag & 7);
579
+ }
580
+ return message;
581
+ },
582
+ };
583
+ function createBaseAttributeValueInput() {
584
+ return { attrId: "", value: "", name: "" };
585
+ }
586
+ exports.AttributeValueInput = {
587
+ encode(message, writer = new wire_1.BinaryWriter()) {
588
+ if (message.attrId !== "") {
589
+ writer.uint32(10).string(message.attrId);
590
+ }
591
+ if (message.value !== "") {
592
+ writer.uint32(18).string(message.value);
593
+ }
594
+ if (message.name !== "") {
595
+ writer.uint32(26).string(message.name);
596
+ }
597
+ return writer;
598
+ },
599
+ decode(input, length) {
600
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
601
+ const end = length === undefined ? reader.len : reader.pos + length;
602
+ const message = createBaseAttributeValueInput();
603
+ while (reader.pos < end) {
604
+ const tag = reader.uint32();
605
+ switch (tag >>> 3) {
606
+ case 1: {
607
+ if (tag !== 10) {
608
+ break;
609
+ }
610
+ message.attrId = reader.string();
611
+ continue;
612
+ }
613
+ case 2: {
614
+ if (tag !== 18) {
615
+ break;
616
+ }
617
+ message.value = reader.string();
618
+ continue;
619
+ }
620
+ case 3: {
621
+ if (tag !== 26) {
622
+ break;
623
+ }
624
+ message.name = reader.string();
625
+ continue;
626
+ }
627
+ }
628
+ if ((tag & 7) === 4 || tag === 0) {
629
+ break;
630
+ }
631
+ reader.skip(tag & 7);
632
+ }
633
+ return message;
634
+ },
635
+ };
636
+ function ProductServiceControllerMethods() {
637
+ return function (constructor) {
638
+ const grpcMethods = ["getProductsByCategoryId", "getProductById", "createProduct"];
639
+ for (const method of grpcMethods) {
640
+ const descriptor = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
641
+ (0, microservices_1.GrpcMethod)("ProductService", method)(constructor.prototype[method], method, descriptor);
642
+ }
643
+ const grpcStreamMethods = [];
644
+ for (const method of grpcStreamMethods) {
645
+ const descriptor = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
646
+ (0, microservices_1.GrpcStreamMethod)("ProductService", method)(constructor.prototype[method], method, descriptor);
647
+ }
648
+ };
649
+ }
650
+ exports.PRODUCT_SERVICE_NAME = "ProductService";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Get the absolute path to a proto file
3
+ * @param protoFileName - The name of the proto file (e.g., 'product.proto')
4
+ * @returns The absolute path to the proto file
5
+ */
6
+ export declare function getProtoPath(protoFileName: string): string;
7
+ /**
8
+ * Get all proto file paths
9
+ * @returns Object with proto file paths
10
+ */
11
+ export declare function getAllProtosPaths(): {
12
+ product: string;
13
+ };
package/dist/utils.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProtoPath = getProtoPath;
4
+ exports.getAllProtosPaths = getAllProtosPaths;
5
+ const path_1 = require("path");
6
+ /**
7
+ * Get the absolute path to a proto file
8
+ * @param protoFileName - The name of the proto file (e.g., 'product.proto')
9
+ * @returns The absolute path to the proto file
10
+ */
11
+ function getProtoPath(protoFileName) {
12
+ return (0, path_1.join)(__dirname, '../proto', protoFileName);
13
+ }
14
+ /**
15
+ * Get all proto file paths
16
+ * @returns Object with proto file paths
17
+ */
18
+ function getAllProtosPaths() {
19
+ return {
20
+ product: getProtoPath('product.proto'),
21
+ };
22
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@sagebox-be/proto-contracts",
3
+ "version": "1.0.0",
4
+ "description": "Sagebox gRPC Protocol Buffer contracts and TypeScript definitions",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*",
9
+ "proto/**/*.proto",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepublishOnly": "npm run build",
15
+ "proto:copy": "cp -r ../common/src/grpc/proto ./proto",
16
+ "proto:generate": "../../bin/proto-generate.sh"
17
+ },
18
+ "keywords": [
19
+ "grpc",
20
+ "protobuf",
21
+ "protocol-buffers",
22
+ "sagebox",
23
+ "typescript"
24
+ ],
25
+ "author": "Sagebox Team",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@grpc/grpc-js": "^1.14.3",
29
+ "@grpc/proto-loader": "^0.8.0",
30
+ "@nestjs/microservices": "^11.1.9",
31
+ "typescript": "^5.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@grpc/grpc-js": "^1.14.0",
35
+ "@grpc/proto-loader": "^0.8.0"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
@@ -0,0 +1,79 @@
1
+ syntax = "proto3";
2
+
3
+ package product;
4
+
5
+ service ProductService {
6
+ rpc GetProductsByCategoryId(GetProductsByCategoryIdRequest) returns (GetProductsResponse);
7
+ rpc GetProductById(GetProductByIdRequest) returns (ProductResponse);
8
+ rpc CreateProduct(CreateProductRequest) returns (ProductResponse);
9
+ }
10
+
11
+ // Request messages
12
+ message GetProductsByCategoryIdRequest {
13
+ string categoryId = 1;
14
+ }
15
+
16
+ message GetProductByIdRequest {
17
+ string id = 1;
18
+ }
19
+
20
+ message CreateProductRequest {
21
+ string name = 1;
22
+ string title = 2;
23
+ string description = 3;
24
+ string categoryId = 4;
25
+ string storeId = 5;
26
+ string status = 6;
27
+ repeated string mediaKeys = 7;
28
+ repeated ProductSkuInput skus = 8;
29
+ }
30
+
31
+ // Response messages
32
+ message GetProductsResponse {
33
+ repeated Product products = 1;
34
+ }
35
+
36
+ message ProductResponse {
37
+ Product product = 1;
38
+ string error = 2;
39
+ }
40
+
41
+ // Data structures
42
+ message Product {
43
+ string id = 1;
44
+ string name = 2;
45
+ string title = 3;
46
+ string description = 4;
47
+ string keywords = 5;
48
+ string categoryId = 6;
49
+ string storeId = 7;
50
+ int32 viewedCount = 8;
51
+ string status = 9;
52
+ string url = 10;
53
+ repeated Media media = 11;
54
+ string createdAt = 12;
55
+ string updatedAt = 13;
56
+ }
57
+
58
+ message Media {
59
+ string id = 1;
60
+ string key = 2;
61
+ string url = 3;
62
+ string type = 4;
63
+ string createdAt = 5;
64
+ string updatedAt = 6;
65
+ }
66
+
67
+ message ProductSkuInput {
68
+ int32 price = 1;
69
+ int32 quantity = 2;
70
+ optional string brand = 3;
71
+ repeated string mediaKeys = 4;
72
+ repeated AttributeValueInput attributeValues = 5;
73
+ }
74
+
75
+ message AttributeValueInput {
76
+ string attrId = 1;
77
+ string value = 2;
78
+ string name = 3;
79
+ }