@scrawn/core 0.0.2 → 0.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 (86) hide show
  1. package/README.md +40 -0
  2. package/dist/gen/auth/v1/auth_grpc_pb.js +45 -0
  3. package/dist/gen/auth/v1/auth_pb.js +471 -86
  4. package/dist/gen/data/v1/data_grpc_pb.js +44 -0
  5. package/dist/gen/data/v1/data_pb.js +1530 -0
  6. package/dist/gen/event/v1/event_grpc_pb.js +79 -0
  7. package/dist/gen/event/v1/event_pb.js +1862 -138
  8. package/dist/gen/package.json +3 -0
  9. package/dist/gen/payment/v1/payment_grpc_pb.js +45 -0
  10. package/dist/gen/payment/v1/payment_pb.js +321 -59
  11. package/dist/gen/query/v1/query_grpc_pb.js +44 -0
  12. package/dist/gen/query/v1/query_pb.js +2327 -0
  13. package/package.json +18 -14
  14. package/dist/config.d.ts +0 -26
  15. package/dist/config.d.ts.map +0 -1
  16. package/dist/config.js +0 -25
  17. package/dist/config.js.map +0 -1
  18. package/dist/core/auth/apiKeyAuth.d.ts +0 -67
  19. package/dist/core/auth/apiKeyAuth.d.ts.map +0 -1
  20. package/dist/core/auth/apiKeyAuth.js +0 -71
  21. package/dist/core/auth/apiKeyAuth.js.map +0 -1
  22. package/dist/core/auth/baseAuth.d.ts +0 -92
  23. package/dist/core/auth/baseAuth.d.ts.map +0 -1
  24. package/dist/core/auth/baseAuth.js +0 -28
  25. package/dist/core/auth/baseAuth.js.map +0 -1
  26. package/dist/core/grpc/client.d.ts +0 -126
  27. package/dist/core/grpc/client.d.ts.map +0 -1
  28. package/dist/core/grpc/client.js +0 -138
  29. package/dist/core/grpc/client.js.map +0 -1
  30. package/dist/core/grpc/index.d.ts +0 -12
  31. package/dist/core/grpc/index.d.ts.map +0 -1
  32. package/dist/core/grpc/index.js +0 -11
  33. package/dist/core/grpc/index.js.map +0 -1
  34. package/dist/core/grpc/requestBuilder.d.ts +0 -116
  35. package/dist/core/grpc/requestBuilder.d.ts.map +0 -1
  36. package/dist/core/grpc/requestBuilder.js +0 -146
  37. package/dist/core/grpc/requestBuilder.js.map +0 -1
  38. package/dist/core/grpc/types.d.ts +0 -54
  39. package/dist/core/grpc/types.d.ts.map +0 -1
  40. package/dist/core/grpc/types.js +0 -9
  41. package/dist/core/grpc/types.js.map +0 -1
  42. package/dist/core/scrawn.d.ts +0 -197
  43. package/dist/core/scrawn.d.ts.map +0 -1
  44. package/dist/core/scrawn.js +0 -331
  45. package/dist/core/scrawn.js.map +0 -1
  46. package/dist/core/types/auth.d.ts +0 -31
  47. package/dist/core/types/auth.d.ts.map +0 -1
  48. package/dist/core/types/auth.js +0 -2
  49. package/dist/core/types/auth.js.map +0 -1
  50. package/dist/core/types/event.d.ts +0 -119
  51. package/dist/core/types/event.d.ts.map +0 -1
  52. package/dist/core/types/event.js +0 -15
  53. package/dist/core/types/event.js.map +0 -1
  54. package/dist/gen/auth/v1/auth_connect.d.ts +0 -22
  55. package/dist/gen/auth/v1/auth_connect.d.ts.map +0 -1
  56. package/dist/gen/auth/v1/auth_connect.js +0 -26
  57. package/dist/gen/auth/v1/auth_connect.js.map +0 -1
  58. package/dist/gen/auth/v1/auth_pb.d.ts +0 -59
  59. package/dist/gen/auth/v1/auth_pb.d.ts.map +0 -1
  60. package/dist/gen/auth/v1/auth_pb.js.map +0 -1
  61. package/dist/gen/event/v1/event_connect.d.ts +0 -22
  62. package/dist/gen/event/v1/event_connect.d.ts.map +0 -1
  63. package/dist/gen/event/v1/event_connect.js +0 -26
  64. package/dist/gen/event/v1/event_connect.js.map +0 -1
  65. package/dist/gen/event/v1/event_pb.d.ts +0 -105
  66. package/dist/gen/event/v1/event_pb.d.ts.map +0 -1
  67. package/dist/gen/event/v1/event_pb.js.map +0 -1
  68. package/dist/gen/payment/v1/payment_connect.d.ts +0 -22
  69. package/dist/gen/payment/v1/payment_connect.d.ts.map +0 -1
  70. package/dist/gen/payment/v1/payment_connect.js +0 -26
  71. package/dist/gen/payment/v1/payment_connect.js.map +0 -1
  72. package/dist/gen/payment/v1/payment_pb.d.ts +0 -37
  73. package/dist/gen/payment/v1/payment_pb.d.ts.map +0 -1
  74. package/dist/gen/payment/v1/payment_pb.js.map +0 -1
  75. package/dist/index.d.ts +0 -11
  76. package/dist/index.d.ts.map +0 -1
  77. package/dist/index.js +0 -15
  78. package/dist/index.js.map +0 -1
  79. package/dist/utils/logger.d.ts +0 -10
  80. package/dist/utils/logger.d.ts.map +0 -1
  81. package/dist/utils/logger.js +0 -62
  82. package/dist/utils/logger.js.map +0 -1
  83. package/dist/utils/pathMatcher.d.ts +0 -25
  84. package/dist/utils/pathMatcher.d.ts.map +0 -1
  85. package/dist/utils/pathMatcher.js +0 -46
  86. package/dist/utils/pathMatcher.js.map +0 -1
@@ -1,11 +0,0 @@
1
- /**
2
- * gRPC abstraction layer - Type-safe fluent API for gRPC calls.
3
- *
4
- * This module provides a beautiful, type-safe interface for making gRPC calls
5
- * with automatic type inference, compile-time validation, and a fluent API.
6
- *
7
- * @module grpc
8
- */
9
- export { GrpcClient } from './client.js';
10
- export { RequestBuilder } from './requestBuilder.js';
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/grpc/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,116 +0,0 @@
1
- /**
2
- * Type-safe fluent API for building and executing gRPC requests.
3
- *
4
- * This module provides a beautiful chain-able interface that ensures:
5
- * - Compile-time type safety for all operations
6
- * - Autocomplete for service methods and payload fields
7
- * - Runtime validation of request state
8
- * - Clean separation of concerns
9
- *
10
- * @example
11
- * ```typescript
12
- * const response = await client
13
- * .newCall(EventService, 'registerEvent')
14
- * .addHeader('x-request-id', '123')
15
- * .addPayload({
16
- * type: EventType.SDK_CALL,
17
- * userId: 'user_123',
18
- * data: { case: 'sdkCall', value: { sdkCallType: SDKCallType.RAW, debitAmount: 10 } }
19
- * })
20
- * .request();
21
- * ```
22
- */
23
- import type { Transport } from '@connectrpc/connect';
24
- import type { ServiceType } from '@bufbuild/protobuf';
25
- import type { ServiceMethodNames, MethodInput, MethodOutput } from './types.js';
26
- /**
27
- * Builder for constructing type-safe gRPC requests.
28
- *
29
- * This class implements a fluent interface where each method returns `this`,
30
- * allowing for method chaining. Type parameters ensure that the payload type
31
- * matches the selected service method at compile time.
32
- *
33
- * @template S - The gRPC service type
34
- * @template M - The method name on the service (string literal)
35
- */
36
- export declare class RequestBuilder<S extends ServiceType, M extends ServiceMethodNames<S>> {
37
- private readonly client;
38
- private readonly methodName;
39
- private readonly headers;
40
- private payload;
41
- private readonly state;
42
- /**
43
- * @internal
44
- * Constructs a new RequestBuilder. Use GrpcClient.newCall() instead.
45
- */
46
- constructor(transport: Transport, service: S, methodName: M);
47
- /**
48
- * Add a header to the request.
49
- *
50
- * Headers are sent with the gRPC call and can be used for authentication,
51
- * tracing, or custom metadata. This method can be called multiple times
52
- * to add multiple headers.
53
- *
54
- * @param key - Header name (e.g., 'authorization', 'x-request-id')
55
- * @param value - Header value
56
- * @returns The builder instance for chaining
57
- *
58
- * @example
59
- * ```typescript
60
- * builder
61
- * .addHeader('authorization', 'Bearer token123')
62
- * .addHeader('x-request-id', 'abc-def-123')
63
- * ```
64
- */
65
- addHeader(key: string, value: string): this;
66
- /**
67
- * Set the request payload.
68
- *
69
- * The payload type is automatically inferred from the service method,
70
- * providing full autocomplete and type checking. This method can only
71
- * be called once per request to prevent accidental overwrites.
72
- *
73
- * @param payload - The request payload (type-checked against the method's input type)
74
- * @returns The builder instance for chaining
75
- * @throws Error if payload has already been set
76
- *
77
- * @example
78
- * ```typescript
79
- * builder.addPayload({
80
- * type: EventType.SDK_CALL,
81
- * userId: 'user_123',
82
- * data: {
83
- * case: 'sdkCall',
84
- * value: {
85
- * sdkCallType: SDKCallType.RAW,
86
- * debitAmount: 10
87
- * }
88
- * }
89
- * })
90
- * ```
91
- */
92
- addPayload(payload: MethodInput<S, M> extends infer T ? Partial<T> : never): this;
93
- /**
94
- * Execute the gRPC request.
95
- *
96
- * Validates that a payload has been set, then makes the actual gRPC call
97
- * using the configured service, method, headers, and payload. The response
98
- * type is automatically inferred from the service method.
99
- *
100
- * @returns A promise that resolves to the typed response
101
- * @throws Error if no payload has been set
102
- * @throws Error if the gRPC call fails
103
- *
104
- * @example
105
- * ```typescript
106
- * const response = await builder
107
- * .addPayload({ userId: 'user_123', ... })
108
- * .request();
109
- *
110
- * // response is fully typed based on the method's output type
111
- * console.log(response.random);
112
- * ```
113
- */
114
- request(): Promise<MethodOutput<S, M>>;
115
- }
116
- //# sourceMappingURL=requestBuilder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requestBuilder.d.ts","sourceRoot":"","sources":["../../../src/core/grpc/requestBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAU,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,YAAY,EAGb,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;GASG;AACH,qBAAa,cAAc,CACzB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAI;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAE7D;;;OAGG;gBAED,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,CAAC,EACV,UAAU,EAAE,CAAC;IAOf;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAK3C;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI;IAajF;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CA6B7C"}
@@ -1,146 +0,0 @@
1
- /**
2
- * Type-safe fluent API for building and executing gRPC requests.
3
- *
4
- * This module provides a beautiful chain-able interface that ensures:
5
- * - Compile-time type safety for all operations
6
- * - Autocomplete for service methods and payload fields
7
- * - Runtime validation of request state
8
- * - Clean separation of concerns
9
- *
10
- * @example
11
- * ```typescript
12
- * const response = await client
13
- * .newCall(EventService, 'registerEvent')
14
- * .addHeader('x-request-id', '123')
15
- * .addPayload({
16
- * type: EventType.SDK_CALL,
17
- * userId: 'user_123',
18
- * data: { case: 'sdkCall', value: { sdkCallType: SDKCallType.RAW, debitAmount: 10 } }
19
- * })
20
- * .request();
21
- * ```
22
- */
23
- import { createClient } from '@connectrpc/connect';
24
- import { ScrawnLogger } from '../../utils/logger.js';
25
- const log = new ScrawnLogger('RequestBuilder');
26
- /**
27
- * Builder for constructing type-safe gRPC requests.
28
- *
29
- * This class implements a fluent interface where each method returns `this`,
30
- * allowing for method chaining. Type parameters ensure that the payload type
31
- * matches the selected service method at compile time.
32
- *
33
- * @template S - The gRPC service type
34
- * @template M - The method name on the service (string literal)
35
- */
36
- export class RequestBuilder {
37
- /**
38
- * @internal
39
- * Constructs a new RequestBuilder. Use GrpcClient.newCall() instead.
40
- */
41
- constructor(transport, service, methodName) {
42
- this.headers = {};
43
- this.payload = null;
44
- this.state = { hasPayload: false };
45
- // Create a typed client for this service
46
- this.client = createClient(service, transport);
47
- this.methodName = methodName;
48
- }
49
- /**
50
- * Add a header to the request.
51
- *
52
- * Headers are sent with the gRPC call and can be used for authentication,
53
- * tracing, or custom metadata. This method can be called multiple times
54
- * to add multiple headers.
55
- *
56
- * @param key - Header name (e.g., 'authorization', 'x-request-id')
57
- * @param value - Header value
58
- * @returns The builder instance for chaining
59
- *
60
- * @example
61
- * ```typescript
62
- * builder
63
- * .addHeader('authorization', 'Bearer token123')
64
- * .addHeader('x-request-id', 'abc-def-123')
65
- * ```
66
- */
67
- addHeader(key, value) {
68
- this.headers[key] = value;
69
- return this;
70
- }
71
- /**
72
- * Set the request payload.
73
- *
74
- * The payload type is automatically inferred from the service method,
75
- * providing full autocomplete and type checking. This method can only
76
- * be called once per request to prevent accidental overwrites.
77
- *
78
- * @param payload - The request payload (type-checked against the method's input type)
79
- * @returns The builder instance for chaining
80
- * @throws Error if payload has already been set
81
- *
82
- * @example
83
- * ```typescript
84
- * builder.addPayload({
85
- * type: EventType.SDK_CALL,
86
- * userId: 'user_123',
87
- * data: {
88
- * case: 'sdkCall',
89
- * value: {
90
- * sdkCallType: SDKCallType.RAW,
91
- * debitAmount: 10
92
- * }
93
- * }
94
- * })
95
- * ```
96
- */
97
- addPayload(payload) {
98
- if (this.state.hasPayload) {
99
- throw new Error('Payload has already been set. Cannot add payload multiple times. ' +
100
- 'Create a new request builder if you need to make another call.');
101
- }
102
- this.payload = payload;
103
- this.state.hasPayload = true;
104
- return this;
105
- }
106
- /**
107
- * Execute the gRPC request.
108
- *
109
- * Validates that a payload has been set, then makes the actual gRPC call
110
- * using the configured service, method, headers, and payload. The response
111
- * type is automatically inferred from the service method.
112
- *
113
- * @returns A promise that resolves to the typed response
114
- * @throws Error if no payload has been set
115
- * @throws Error if the gRPC call fails
116
- *
117
- * @example
118
- * ```typescript
119
- * const response = await builder
120
- * .addPayload({ userId: 'user_123', ... })
121
- * .request();
122
- *
123
- * // response is fully typed based on the method's output type
124
- * console.log(response.random);
125
- * ```
126
- */
127
- async request() {
128
- if (!this.state.hasPayload || this.payload === null) {
129
- throw new Error('Cannot make request without payload. Call addPayload() first.');
130
- }
131
- try {
132
- log.info(`Making gRPC call to ${this.methodName}`);
133
- log.debug(`Headers: ${JSON.stringify(this.headers)}`);
134
- log.debug(`Payload: ${JSON.stringify(this.payload)}`);
135
- // The actual gRPC call - fully type-safe!
136
- const response = await this.client[this.methodName](this.payload, { headers: this.headers });
137
- log.info(`Successfully completed gRPC call to ${this.methodName}`);
138
- return response;
139
- }
140
- catch (error) {
141
- log.error(`gRPC call to ${this.methodName} failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
142
- throw error;
143
- }
144
- }
145
- }
146
- //# sourceMappingURL=requestBuilder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requestBuilder.js","sourceRoot":"","sources":["../../../src/core/grpc/requestBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AASrD,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAc;IAUzB;;;OAGG;IACH,YACE,SAAoB,EACpB,OAAU,EACV,UAAa;QAXE,YAAO,GAAY,EAAE,CAAC;QAC/B,YAAO,GAAQ,IAAI,CAAC;QACX,UAAK,GAAiB,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;QAW3D,yCAAyC;QACzC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,GAAW,EAAE,KAAa;QAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,UAAU,CAAC,OAA+D;QACxE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CACb,mEAAmE;gBACnE,gEAAgE,CACjE,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,GAAG,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;YACnD,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtD,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAEtD,0CAA0C;YAC1C,MAAM,QAAQ,GAAG,MAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAS,CAC1D,IAAI,CAAC,OAAO,EACZ,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAC1B,CAAC;YAEF,GAAG,CAAC,IAAI,CAAC,uCAAuC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;YACnE,OAAO,QAA8B,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,CACP,gBAAgB,IAAI,CAAC,UAAU,YAC7B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAC3C,EAAE,CACH,CAAC;YACF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -1,54 +0,0 @@
1
- /**
2
- * Core type system for the gRPC client abstraction layer.
3
- *
4
- * This module provides compile-time type safety for all gRPC operations,
5
- * ensuring that payloads, headers, and responses are correctly typed based
6
- * on the service and method being called.
7
- */
8
- import type { ServiceType } from '@bufbuild/protobuf';
9
- import type { MessageType } from '@bufbuild/protobuf';
10
- /**
11
- * Extract all method names from a service as a union of string literals.
12
- * This provides autocomplete and compile-time validation of method names.
13
- */
14
- export type ServiceMethodNames<S extends ServiceType> = keyof S['methods'] & string;
15
- /**
16
- * Get the input MessageType (constructor) for a specific method on a service.
17
- */
18
- export type MethodInputType<S extends ServiceType, M extends ServiceMethodNames<S>> = S['methods'][M] extends {
19
- I: infer I;
20
- } ? I : never;
21
- /**
22
- * Get the output MessageType (constructor) for a specific method on a service.
23
- */
24
- export type MethodOutputType<S extends ServiceType, M extends ServiceMethodNames<S>> = S['methods'][M] extends {
25
- O: infer O;
26
- } ? O : never;
27
- /**
28
- * Convert a MessageType to its Message instance type.
29
- * This extracts the actual Message type from a MessageType constructor.
30
- */
31
- export type MessageTypeToMessage<T> = T extends MessageType<infer M> ? M : never;
32
- /**
33
- * Get the input Message type for a specific method on a service.
34
- * This is what you'll use for the payload type.
35
- */
36
- export type MethodInput<S extends ServiceType, M extends ServiceMethodNames<S>> = MessageTypeToMessage<MethodInputType<S, M>>;
37
- /**
38
- * Get the output Message type for a specific method on a service.
39
- * This is what you'll get back from the request.
40
- */
41
- export type MethodOutput<S extends ServiceType, M extends ServiceMethodNames<S>> = MessageTypeToMessage<MethodOutputType<S, M>>;
42
- /**
43
- * HTTP headers as key-value pairs.
44
- */
45
- export interface Headers {
46
- [key: string]: string;
47
- }
48
- /**
49
- * State tracking for the request builder to prevent duplicate operations.
50
- */
51
- export interface RequestState {
52
- hasPayload: boolean;
53
- }
54
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/grpc/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;AAEpF;;GAEG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,IAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,IAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEjF;;;GAGG;AACH,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,IAC7B,oBAAoB,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEhD;;;GAGG;AACH,MAAM,MAAM,YAAY,CACtB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,IAC7B,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,OAAO,CAAC;CACrB"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Core type system for the gRPC client abstraction layer.
3
- *
4
- * This module provides compile-time type safety for all gRPC operations,
5
- * ensuring that payloads, headers, and responses are correctly typed based
6
- * on the service and method being called.
7
- */
8
- export {};
9
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/grpc/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -1,197 +0,0 @@
1
- import type { EventPayload, MiddlewareRequest, MiddlewareResponse, MiddlewareNext, MiddlewareEventConfig } from './types/event.js';
2
- import type { AllCredentials } from './types/auth.js';
3
- /**
4
- * Main SDK class for Scrawn billing infrastructure.
5
- *
6
- * Manages authentication, event tracking, and credential caching.
7
- * All event consumption methods are available directly on the SDK instance.
8
- *
9
- * @example
10
- * ```typescript
11
- * import { Scrawn } from '@scrawn/core';
12
- *
13
- * // Initialize SDK
14
- * const scrawn = new Scrawn({ apiKey: process.env.SCRAWN_KEY });
15
- * await scrawn.init();
16
- *
17
- * // Track SDK calls
18
- * await scrawn.sdkCallEventConsumer({ userId: 'u123', debitAmount: 3 });
19
- * ```
20
- */
21
- export declare class Scrawn {
22
- /** Map of authentication method names to their implementations */
23
- private authMethods;
24
- /**
25
- * Cache of credentials keyed by auth method name for performance.
26
- * Keys are restricted to registered auth method names only.
27
- */
28
- private credCache;
29
- /** API key used for default authentication */
30
- private apiKey;
31
- /** gRPC client for making type-safe API calls */
32
- private grpcClient;
33
- /**
34
- * Creates a new Scrawn SDK instance.
35
- *
36
- * @param config - Configuration object
37
- * @param config.apiKey - Your Scrawn API key for authentication
38
- * @param config.baseURL - Base URL for the Scrawn API (e.g., 'https://api.scrawn.dev')
39
- *
40
- * @example
41
- * ```typescript
42
- * const scrawn = new Scrawn({
43
- * apiKey: 'sk_test_...',
44
- * baseURL: 'https://api.scrawn.dev'
45
- * });
46
- * await scrawn.init();
47
- * ```
48
- */
49
- constructor(config: {
50
- apiKey: AllCredentials['apiKey'];
51
- baseURL: string;
52
- });
53
- /**
54
- * Register an authentication method with the SDK.
55
- *
56
- * Auth methods handle credential management and can be shared across multiple event types.
57
- * Only auth method names defined in AuthRegistry are allowed.
58
- *
59
- * @param name - Unique identifier for this auth method (must be in AuthRegistry)
60
- * @param auth - Instance of an AuthBase implementation
61
- *
62
- * @example
63
- * ```typescript
64
- * scrawn.registerAuthMethod('api', new ApiKeyAuth('sk_test_...'));
65
- * ```
66
- */
67
- private registerAuthMethod;
68
- /**
69
- * Get credentials for a specific authentication method.
70
- *
71
- * Credentials are cached after the first fetch for performance.
72
- * Subsequent calls return the cached value without re-fetching.
73
- * Only auth method names defined in AuthRegistry are allowed.
74
- *
75
- * @param authMethodName - Name of the auth method to get credentials for (must be in AuthRegistry)
76
- * @returns A promise that resolves to the credentials object
77
- * @throws Error if the auth method is not registered
78
- *
79
- * @example
80
- * ```typescript
81
- * const creds = await scrawn.getCredsFor('api');
82
- * // { apiKey: 'sk_test_...' }
83
- * ```
84
- */
85
- private getCredsFor;
86
- /**
87
- * Track an SDK call event.
88
- *
89
- * Records SDK usage to the Scrawn backend for billing tracking.
90
- * The event is authenticated using the API key provided during SDK initialization.
91
- *
92
- * @param payload - The SDK call data to track
93
- * @param payload.userId - Unique identifier of the user making the call
94
- * @param payload.debitAmount - Amount to debit from the user's account
95
- * @returns A promise that resolves when the event is tracked
96
- * @throws Error if payload validation fails
97
- *
98
- * @example
99
- * ```typescript
100
- * await scrawn.sdkCallEventConsumer({
101
- * userId: 'user_abc123',
102
- * debitAmount: 10
103
- * });
104
- * ```
105
- */
106
- sdkCallEventConsumer(payload: EventPayload): Promise<void>;
107
- /**
108
- * Create an Express-compatible middleware for tracking API endpoint usage.
109
- *
110
- * This middleware automatically tracks requests to your API endpoints for billing purposes.
111
- * You provide an extractor function that determines the userId and debitAmount from each request.
112
- * Optionally, you can provide a whitelist array to only track specific endpoints,
113
- * or a blacklist array to exclude specific endpoints from tracking.
114
- *
115
- * The middleware is framework-agnostic and works with Express, Fastify, and similar frameworks.
116
- *
117
- * @param config - Configuration object for the middleware
118
- * @param config.extractor - Function that extracts userId and debitAmount from the request. Return null to skip tracking.
119
- * @param config.whitelist - Optional array of endpoint patterns to track. Supports wildcards:
120
- * - Exact match: /api/users
121
- * - Single segment (*): /api/* matches /api/users but not /api/users/123
122
- * - Multi-segment (**): /api/** matches any path starting with /api/
123
- * - Mixed: /api/star/profile, **.php
124
- * Takes precedence over blacklist. If omitted, all requests will be tracked.
125
- * @param config.blacklist - Optional array of endpoint patterns to exclude. Same wildcard support as whitelist.
126
- * Only applies to endpoints not in the whitelist.
127
- *
128
- * @returns Express-compatible middleware function
129
- *
130
- * @example
131
- * ```typescript
132
- * // Track all endpoints
133
- * app.use(scrawn.middlewareEventConsumer({
134
- * extractor: (req) => ({
135
- * userId: req.user.id,
136
- * debitAmount: 1
137
- * })
138
- * }));
139
- *
140
- * // Track only specific endpoints with wildcards
141
- * app.use(scrawn.middlewareEventConsumer({
142
- * extractor: (req) => ({
143
- * userId: req.headers['x-user-id'] as string,
144
- * debitAmount: req.body.tokens || 1
145
- * }),
146
- * whitelist: ['/api/generate', '/api/analyze', '/api/v1/*']
147
- * }));
148
- *
149
- * // Exclude specific endpoints from tracking
150
- * app.use(scrawn.middlewareEventConsumer({
151
- * extractor: (req) => ({
152
- * userId: req.user.id,
153
- * debitAmount: 1
154
- * }),
155
- * blacklist: ['/health', '/api/collect-payment', '/internal/**', '**.tmp']
156
- * }));
157
- * ```
158
- */
159
- middlewareEventConsumer(config: MiddlewareEventConfig): (req: MiddlewareRequest, res: MiddlewareResponse, next: MiddlewareNext) => Promise<void>;
160
- /**
161
- * Collect payment by creating a checkout link for a user.
162
- *
163
- * Generates a payment checkout link for the specified user via the Scrawn payment service.
164
- * The checkout link can be used to direct users to complete their payment.
165
- *
166
- * @param userId - Unique identifier of the user to collect payment from
167
- * @returns A promise that resolves to the checkout link URL
168
- * @throws Error if the gRPC call fails or if authentication is invalid
169
- *
170
- * @example
171
- * ```typescript
172
- * const checkoutLink = await scrawn.collectPayment('user_abc123');
173
- * // Returns: 'https://checkout.scrawn.dev/...'
174
- * // Redirect user to this URL to complete payment
175
- * ```
176
- */
177
- collectPayment(userId: string): Promise<string>;
178
- /**
179
- * Internal method to consume and process an event.
180
- *
181
- * This method:
182
- * 1. Validates authentication
183
- * 2. Fetches/caches credentials
184
- * 3. Executes any pre-run hooks
185
- * 4. Processes the event via gRPC call to RegisterEvent
186
- *
187
- * @param payload - Event payload data
188
- * @param authMethodName - Name of the auth method to use (must be in AuthRegistry)
189
- * @param eventType - Type of event for categorization (RAW or MIDDLEWARE_CALL)
190
- * @returns A promise that resolves when the event is processed
191
- * @throws Error if auth method is not registered or gRPC call fails
192
- *
193
- * @internal
194
- */
195
- private consumeEvent;
196
- }
197
- //# sourceMappingURL=scrawn.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scrawn.d.ts","sourceRoot":"","sources":["../../src/core/scrawn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAgC,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAYpF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,MAAM;IACjB,kEAAkE;IAClE,OAAO,CAAC,WAAW,CAAuD;IAE1E;;;OAGG;IACH,OAAO,CAAC,SAAS,CAA6C;IAE9D,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAA2B;IAEzC,iDAAiD;IACjD,OAAO,CAAC,UAAU,CAAa;IAE/B;;;;;;;;;;;;;;;OAeG;gBACS,MAAM,EAAE;QAAE,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAWzE;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;;;;;;;;;;;;;;OAgBG;YACW,WAAW;IAmBzB;;;;;;;;;;;;;;;;;;;OAmBG;IACG,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAWhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmDG;IACH,uBAAuB,CAAC,MAAM,EAAE,qBAAqB,IACrC,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc;IAkDrF;;;;;;;;;;;;;;;;OAgBG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BrD;;;;;;;;;;;;;;;;OAgBG;YACW,YAAY;CA8C3B"}