@scrawn/core 0.0.3 → 0.0.7
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/dist/config.d.ts +41 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +32 -0
- package/dist/config.js.map +1 -0
- package/dist/core/auth/apiKeyAuth.d.ts +58 -0
- package/dist/core/auth/apiKeyAuth.d.ts.map +1 -0
- package/dist/core/auth/apiKeyAuth.js +66 -0
- package/dist/core/auth/apiKeyAuth.js.map +1 -0
- package/dist/core/auth/baseAuth.d.ts +70 -0
- package/dist/core/auth/baseAuth.d.ts.map +1 -0
- package/dist/core/auth/baseAuth.js +22 -0
- package/dist/core/auth/baseAuth.js.map +1 -0
- package/dist/core/errors/index.d.ts +192 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/core/errors/index.js +280 -0
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/grpc/callContext.d.ts +18 -0
- package/dist/core/grpc/callContext.d.ts.map +1 -0
- package/dist/core/grpc/callContext.js +35 -0
- package/dist/core/grpc/callContext.js.map +1 -0
- package/dist/core/grpc/client.d.ts +16 -0
- package/dist/core/grpc/client.d.ts.map +1 -0
- package/dist/core/grpc/client.js +30 -0
- package/dist/core/grpc/client.js.map +1 -0
- package/dist/core/grpc/index.d.ts +14 -0
- package/dist/core/grpc/index.d.ts.map +1 -0
- package/dist/core/grpc/index.js +13 -0
- package/dist/core/grpc/index.js.map +1 -0
- package/dist/core/grpc/requestBuilder.d.ts +15 -0
- package/dist/core/grpc/requestBuilder.d.ts.map +1 -0
- package/dist/core/grpc/requestBuilder.js +56 -0
- package/dist/core/grpc/requestBuilder.js.map +1 -0
- package/dist/core/grpc/streamRequestBuilder.d.ts +13 -0
- package/dist/core/grpc/streamRequestBuilder.d.ts.map +1 -0
- package/dist/core/grpc/streamRequestBuilder.js +60 -0
- package/dist/core/grpc/streamRequestBuilder.js.map +1 -0
- package/dist/core/grpc/types.d.ts +7 -0
- package/dist/core/grpc/types.d.ts.map +1 -0
- package/dist/core/grpc/types.js +2 -0
- package/dist/core/grpc/types.js.map +1 -0
- package/dist/core/pricing/builders.d.ts +157 -0
- package/dist/core/pricing/builders.d.ts.map +1 -0
- package/dist/core/pricing/builders.js +218 -0
- package/dist/core/pricing/builders.js.map +1 -0
- package/dist/core/pricing/index.d.ts +30 -0
- package/dist/core/pricing/index.d.ts.map +1 -0
- package/dist/core/pricing/index.js +32 -0
- package/dist/core/pricing/index.js.map +1 -0
- package/dist/core/pricing/resolve.d.ts +39 -0
- package/dist/core/pricing/resolve.d.ts.map +1 -0
- package/dist/core/pricing/resolve.js +50 -0
- package/dist/core/pricing/resolve.js.map +1 -0
- package/dist/core/pricing/serialize.d.ts +55 -0
- package/dist/core/pricing/serialize.d.ts.map +1 -0
- package/dist/core/pricing/serialize.js +127 -0
- package/dist/core/pricing/serialize.js.map +1 -0
- package/dist/core/pricing/types.d.ts +122 -0
- package/dist/core/pricing/types.d.ts.map +1 -0
- package/dist/core/pricing/types.js +17 -0
- package/dist/core/pricing/types.js.map +1 -0
- package/dist/core/pricing/validate.d.ts +56 -0
- package/dist/core/pricing/validate.d.ts.map +1 -0
- package/dist/core/pricing/validate.js +162 -0
- package/dist/core/pricing/validate.js.map +1 -0
- package/dist/core/scrawn.d.ts +414 -0
- package/dist/core/scrawn.d.ts.map +1 -0
- package/dist/core/scrawn.js +822 -0
- package/dist/core/scrawn.js.map +1 -0
- package/dist/core/types/auth.d.ts +31 -0
- package/dist/core/types/auth.d.ts.map +1 -0
- package/dist/core/types/auth.js +2 -0
- package/dist/core/types/auth.js.map +1 -0
- package/dist/core/types/event.d.ts +320 -0
- package/dist/core/types/event.d.ts.map +1 -0
- package/dist/core/types/event.js +155 -0
- package/dist/core/types/event.js.map +1 -0
- package/dist/gen/auth/v1/auth_grpc_pb.d.ts +3 -0
- package/dist/gen/auth/v1/auth_pb.d.ts +65 -0
- package/dist/gen/data/v1/data_grpc_pb.d.ts +5 -0
- package/dist/gen/data/v1/data_pb.d.ts +254 -0
- package/dist/gen/event/v1/event_grpc_pb.d.ts +3 -0
- package/dist/gen/event/v1/event_pb.d.ts +342 -0
- package/dist/gen/event/v1/event_pb.js +573 -117
- package/dist/gen/payment/v1/payment_grpc_pb.d.ts +3 -0
- package/dist/gen/payment/v1/payment_pb.d.ts +45 -0
- package/dist/gen/query/v1/query_grpc_pb.d.ts +5 -0
- package/dist/gen/query/v1/query_pb.d.ts +381 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/forkAsyncIterable.d.ts +13 -0
- package/dist/utils/forkAsyncIterable.d.ts.map +1 -0
- package/dist/utils/forkAsyncIterable.js +78 -0
- package/dist/utils/forkAsyncIterable.js.map +1 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +62 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/pathMatcher.d.ts +25 -0
- package/dist/utils/pathMatcher.d.ts.map +1 -0
- package/dist/utils/pathMatcher.js +46 -0
- package/dist/utils/pathMatcher.js.map +1 -0
- package/package.json +2 -2
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central configuration for the Scrawn SDK.
|
|
3
|
+
* All configuration values should be defined here for easy maintenance.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ScrawnConfig: {
|
|
6
|
+
/**
|
|
7
|
+
* gRPC client configuration
|
|
8
|
+
*/
|
|
9
|
+
readonly grpc: {
|
|
10
|
+
/**
|
|
11
|
+
* Default gRPC port
|
|
12
|
+
*/
|
|
13
|
+
readonly defaultPort: 8069;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Logging configuration
|
|
17
|
+
*/
|
|
18
|
+
readonly logging: {
|
|
19
|
+
/**
|
|
20
|
+
* Enable debug logs
|
|
21
|
+
*/
|
|
22
|
+
readonly enableDebug: false;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type ScrawnConfig = typeof ScrawnConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for the Scrawn CLI (`scrawn tag sync`).
|
|
28
|
+
* Used in the project's `scrawn.config.ts` file.
|
|
29
|
+
*/
|
|
30
|
+
export interface ScrawnCLIConfig {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
grpcUrl: string;
|
|
33
|
+
httpUrl: string;
|
|
34
|
+
directory: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Type-safe helper for defining project configuration in `scrawn.config.ts`.
|
|
38
|
+
* Returns the config unchanged — purely a type-witness.
|
|
39
|
+
*/
|
|
40
|
+
export declare function scrawnConfig(config: ScrawnCLIConfig): ScrawnCLIConfig;
|
|
41
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,YAAY;IACvB;;OAEG;;QAED;;WAEG;;;IAIL;;OAEG;;QAED;;WAEG;;;CAGG,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAErE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central configuration for the Scrawn SDK.
|
|
3
|
+
* All configuration values should be defined here for easy maintenance.
|
|
4
|
+
*/
|
|
5
|
+
export const ScrawnConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* gRPC client configuration
|
|
8
|
+
*/
|
|
9
|
+
grpc: {
|
|
10
|
+
/**
|
|
11
|
+
* Default gRPC port
|
|
12
|
+
*/
|
|
13
|
+
defaultPort: 8069,
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* Logging configuration
|
|
17
|
+
*/
|
|
18
|
+
logging: {
|
|
19
|
+
/**
|
|
20
|
+
* Enable debug logs
|
|
21
|
+
*/
|
|
22
|
+
enableDebug: false,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Type-safe helper for defining project configuration in `scrawn.config.ts`.
|
|
27
|
+
* Returns the config unchanged — purely a type-witness.
|
|
28
|
+
*/
|
|
29
|
+
export function scrawnConfig(config) {
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B;;OAEG;IACH,IAAI,EAAE;QACJ;;WAEG;QACH,WAAW,EAAE,IAAI;KAClB;IAED;;OAEG;IACH,OAAO,EAAE;QACP;;WAEG;QACH,WAAW,EAAE,KAAK;KACnB;CACO,CAAC;AAeX;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAuB;IAClD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AuthBase } from "./baseAuth.js";
|
|
2
|
+
/**
|
|
3
|
+
* API key format: scrn_<role>_ followed by 32 alphanumeric characters.
|
|
4
|
+
* Roles: dash (dashboard), live (production), test
|
|
5
|
+
* @example 'scrn_live_abc123def456ghi789jkl012mno345pq'
|
|
6
|
+
*/
|
|
7
|
+
export type ApiKeyFormat = `scrn_${string}`;
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to validate API key format
|
|
10
|
+
*/
|
|
11
|
+
export declare function isValidApiKey(key: string): key is ApiKeyFormat;
|
|
12
|
+
/**
|
|
13
|
+
* Validates and returns a properly typed API key
|
|
14
|
+
* @throws Error if the API key format is invalid
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateApiKey(key: string): ApiKeyFormat;
|
|
17
|
+
/**
|
|
18
|
+
* Credentials structure for API key authentication.
|
|
19
|
+
*/
|
|
20
|
+
export type ApiKeyAuthCreds = {
|
|
21
|
+
apiKey: ApiKeyFormat;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Simple API key authentication method.
|
|
25
|
+
*
|
|
26
|
+
* Provides authentication using a static API key.
|
|
27
|
+
* This is the default authentication method registered by the SDK.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const auth = new ApiKeyAuth('sk_test_...');
|
|
32
|
+
* scrawn.registerAuthMethod('api', auth);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class ApiKeyAuth extends AuthBase<ApiKeyAuthCreds> {
|
|
36
|
+
/** Validated API key */
|
|
37
|
+
private validatedKey;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new API key authentication instance.
|
|
40
|
+
*
|
|
41
|
+
* @param apiKey - Your Scrawn API key (format: sk_<16 alphanumeric chars>)
|
|
42
|
+
* @throws Error if API key format is invalid
|
|
43
|
+
*/
|
|
44
|
+
constructor(apiKey: string);
|
|
45
|
+
/**
|
|
46
|
+
* Get the API key credentials.
|
|
47
|
+
*
|
|
48
|
+
* @returns A promise that resolves to an object containing the API key
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const creds = await auth.getCreds();
|
|
53
|
+
* // { apiKey: 'sk_abc123def456ghi7' }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
getCreds(): Promise<ApiKeyAuthCreds>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=apiKeyAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKeyAuth.d.ts","sourceRoot":"","sources":["../../../src/core/auth/apiKeyAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAMzC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,MAAM,EAAE,CAAC;AAI5C;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,YAAY,CAE9D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAcxD;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,UAAW,SAAQ,QAAQ,CAAC,eAAe,CAAC;IACvD,wBAAwB;IACxB,OAAO,CAAC,YAAY,CAAe;IAEnC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM;IAK1B;;;;;;;;;;OAUG;IACG,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC;CAG3C"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AuthBase } from "./baseAuth.js";
|
|
2
|
+
import { ScrawnLogger } from "../../utils/logger.js";
|
|
3
|
+
import { ScrawnValidationError } from "../errors/index.js";
|
|
4
|
+
const log = new ScrawnLogger("Auth");
|
|
5
|
+
const API_KEY_REGEX = /^scrn_(dash|live|test)_[a-zA-Z0-9]{32}$/;
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to validate API key format
|
|
8
|
+
*/
|
|
9
|
+
export function isValidApiKey(key) {
|
|
10
|
+
return API_KEY_REGEX.test(key);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Validates and returns a properly typed API key
|
|
14
|
+
* @throws Error if the API key format is invalid
|
|
15
|
+
*/
|
|
16
|
+
export function validateApiKey(key) {
|
|
17
|
+
if (!isValidApiKey(key)) {
|
|
18
|
+
log.error(`Invalid API key format: "${key}".`);
|
|
19
|
+
throw new ScrawnValidationError("Invalid API key format. Expected format: scrn_<dash|live|test>_<32 alphanumeric characters>", {
|
|
20
|
+
details: {
|
|
21
|
+
providedKey: key.substring(0, 14) + "...",
|
|
22
|
+
expectedFormat: "scrn_<role>_<32 alphanumeric characters>",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return key;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Simple API key authentication method.
|
|
30
|
+
*
|
|
31
|
+
* Provides authentication using a static API key.
|
|
32
|
+
* This is the default authentication method registered by the SDK.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const auth = new ApiKeyAuth('sk_test_...');
|
|
37
|
+
* scrawn.registerAuthMethod('api', auth);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class ApiKeyAuth extends AuthBase {
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new API key authentication instance.
|
|
43
|
+
*
|
|
44
|
+
* @param apiKey - Your Scrawn API key (format: sk_<16 alphanumeric chars>)
|
|
45
|
+
* @throws Error if API key format is invalid
|
|
46
|
+
*/
|
|
47
|
+
constructor(apiKey) {
|
|
48
|
+
super();
|
|
49
|
+
this.validatedKey = validateApiKey(apiKey);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the API key credentials.
|
|
53
|
+
*
|
|
54
|
+
* @returns A promise that resolves to an object containing the API key
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const creds = await auth.getCreds();
|
|
59
|
+
* // { apiKey: 'sk_abc123def456ghi7' }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async getCreds() {
|
|
63
|
+
return { apiKey: this.validatedKey };
|
|
64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AC,YAAY,EAAE,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for authentication methods.
|
|
3
|
+
*
|
|
4
|
+
* All authentication implementations must extend this class and implement the required methods.
|
|
5
|
+
* Auth methods are responsible for managing and providing credentials for API requests.
|
|
6
|
+
*
|
|
7
|
+
* @template TCreds - The type of credentials this auth method returns
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* type MyAuthCreds = { token: string };
|
|
12
|
+
*
|
|
13
|
+
* export class MyAuth extends AuthBase<MyAuthCreds> {
|
|
14
|
+
* async getCreds(): Promise<MyAuthCreds> {
|
|
15
|
+
* return { token: 'my_token' };
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class AuthBase<TCreds = unknown> {
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve the current credentials for this authentication method.
|
|
23
|
+
*
|
|
24
|
+
* This method is called whenever an event needs to authenticate.
|
|
25
|
+
* Credentials are cached by the SDK, so this is typically only called once.
|
|
26
|
+
*
|
|
27
|
+
* @returns A promise that resolves to the credentials object
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* async getCreds(): Promise<MyAuthCreds> {
|
|
32
|
+
* return { apiKey: this.apiKey };
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
abstract getCreds(): Promise<TCreds>;
|
|
37
|
+
/**
|
|
38
|
+
* Optional hook that runs before each event is processed.
|
|
39
|
+
*
|
|
40
|
+
* Use this for operations that must happen before every request,
|
|
41
|
+
* such as token refresh checks or rate limiting.
|
|
42
|
+
*
|
|
43
|
+
* @returns A promise that resolves when the pre-run hook completes
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* async preRun() {
|
|
48
|
+
* await this.refreshTokenIfNeeded();
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
preRun?(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Optional hook that runs after each event is processed.
|
|
55
|
+
*
|
|
56
|
+
* Use this for cleanup operations or logging that should happen
|
|
57
|
+
* after every request completes.
|
|
58
|
+
*
|
|
59
|
+
* @returns A promise that resolves when the post-run hook completes
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* async postRun() {
|
|
64
|
+
* await this.logRequestMetrics();
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
postRun?(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=baseAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseAuth.d.ts","sourceRoot":"","sources":["../../../src/core/auth/baseAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,8BAAsB,QAAQ,CAAC,MAAM,GAAG,OAAO;IAC7C;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAEpC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAC1B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for authentication methods.
|
|
3
|
+
*
|
|
4
|
+
* All authentication implementations must extend this class and implement the required methods.
|
|
5
|
+
* Auth methods are responsible for managing and providing credentials for API requests.
|
|
6
|
+
*
|
|
7
|
+
* @template TCreds - The type of credentials this auth method returns
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* type MyAuthCreds = { token: string };
|
|
12
|
+
*
|
|
13
|
+
* export class MyAuth extends AuthBase<MyAuthCreds> {
|
|
14
|
+
* async getCreds(): Promise<MyAuthCreds> {
|
|
15
|
+
* return { token: 'my_token' };
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class AuthBase {
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=baseAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseAuth.js","sourceRoot":"","sources":["../../../src/core/auth/baseAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAgB,QAAQ;CAmD7B"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive error handling system for the Scrawn SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides structured error classes with rich metadata for better debugging
|
|
5
|
+
* and error handling by SDK consumers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* try {
|
|
10
|
+
* await scrawn.basicUsageEventConsumer({ ... });
|
|
11
|
+
* } catch (error) {
|
|
12
|
+
* if (error instanceof ScrawnAuthenticationError) {
|
|
13
|
+
* console.error('Auth failed:', error.message);
|
|
14
|
+
* // Refresh API key
|
|
15
|
+
* } else if (error instanceof ScrawnNetworkError && error.retryable) {
|
|
16
|
+
* // Retry the request
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Base error class for all Scrawn SDK errors.
|
|
23
|
+
* Extends native Error with additional metadata fields.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ScrawnError extends Error {
|
|
26
|
+
/** Error code for programmatic error handling */
|
|
27
|
+
readonly code: string;
|
|
28
|
+
/** Whether this error is retryable */
|
|
29
|
+
readonly retryable: boolean;
|
|
30
|
+
/** HTTP status code if applicable */
|
|
31
|
+
readonly statusCode?: number;
|
|
32
|
+
/** Request ID for debugging (if available) */
|
|
33
|
+
readonly requestId?: string;
|
|
34
|
+
/** Additional error details */
|
|
35
|
+
readonly details?: Record<string, any>;
|
|
36
|
+
/** Original error that caused this error (if any) */
|
|
37
|
+
readonly cause?: Error;
|
|
38
|
+
constructor(message: string, options: {
|
|
39
|
+
code: string;
|
|
40
|
+
retryable?: boolean;
|
|
41
|
+
statusCode?: number;
|
|
42
|
+
requestId?: string;
|
|
43
|
+
details?: Record<string, any>;
|
|
44
|
+
cause?: Error;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Convert error to a plain object for logging/serialization.
|
|
48
|
+
*/
|
|
49
|
+
toJSON(): {
|
|
50
|
+
name: string;
|
|
51
|
+
code: string;
|
|
52
|
+
message: string;
|
|
53
|
+
retryable: boolean;
|
|
54
|
+
statusCode: number | undefined;
|
|
55
|
+
requestId: string | undefined;
|
|
56
|
+
details: Record<string, any> | undefined;
|
|
57
|
+
stack: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Authentication or authorization error (401, 403).
|
|
62
|
+
* Thrown when API key is invalid, expired, or lacks permissions.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* throw new ScrawnAuthenticationError('Invalid API key', {
|
|
67
|
+
* statusCode: 401,
|
|
68
|
+
* requestId: 'req_123'
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare class ScrawnAuthenticationError extends ScrawnError {
|
|
73
|
+
constructor(message: string, options?: {
|
|
74
|
+
statusCode?: number;
|
|
75
|
+
requestId?: string;
|
|
76
|
+
details?: Record<string, any>;
|
|
77
|
+
cause?: Error;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validation error (400).
|
|
82
|
+
* Thrown when request payload fails validation.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* throw new ScrawnValidationError('Invalid userId', {
|
|
87
|
+
* details: { field: 'userId', constraint: 'non-empty' }
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare class ScrawnValidationError extends ScrawnError {
|
|
92
|
+
constructor(message: string, options?: {
|
|
93
|
+
requestId?: string;
|
|
94
|
+
details?: Record<string, any>;
|
|
95
|
+
cause?: Error;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Rate limit error (429).
|
|
100
|
+
* Thrown when API rate limits are exceeded.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* throw new ScrawnRateLimitError('Rate limit exceeded', {
|
|
105
|
+
* details: { retryAfter: 60 }
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare class ScrawnRateLimitError extends ScrawnError {
|
|
110
|
+
/** Seconds to wait before retrying (if provided by API) */
|
|
111
|
+
readonly retryAfter?: number;
|
|
112
|
+
constructor(message: string, options?: {
|
|
113
|
+
requestId?: string;
|
|
114
|
+
retryAfter?: number;
|
|
115
|
+
details?: Record<string, any>;
|
|
116
|
+
cause?: Error;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Network-related error (timeout, connection failure, DNS issues).
|
|
121
|
+
* These are typically retryable.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* throw new ScrawnNetworkError('Connection timeout', {
|
|
126
|
+
* cause: originalError,
|
|
127
|
+
* details: { timeout: 30000 }
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare class ScrawnNetworkError extends ScrawnError {
|
|
132
|
+
constructor(message: string, options?: {
|
|
133
|
+
requestId?: string;
|
|
134
|
+
details?: Record<string, any>;
|
|
135
|
+
cause?: Error;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* API error from the Scrawn backend (5xx or other server errors).
|
|
140
|
+
* May be retryable depending on status code.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* throw new ScrawnAPIError('Internal server error', {
|
|
145
|
+
* statusCode: 500,
|
|
146
|
+
* retryable: true,
|
|
147
|
+
* requestId: 'req_123'
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare class ScrawnAPIError extends ScrawnError {
|
|
152
|
+
constructor(message: string, options: {
|
|
153
|
+
statusCode: number;
|
|
154
|
+
requestId?: string;
|
|
155
|
+
retryable?: boolean;
|
|
156
|
+
details?: Record<string, any>;
|
|
157
|
+
cause?: Error;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Configuration error (invalid SDK initialization or settings).
|
|
162
|
+
* Not retryable - requires code changes.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* throw new ScrawnConfigError('Invalid baseURL format', {
|
|
167
|
+
* details: { baseURL: 'invalid-url' }
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export declare class ScrawnConfigError extends ScrawnError {
|
|
172
|
+
constructor(message: string, options?: {
|
|
173
|
+
details?: Record<string, any>;
|
|
174
|
+
cause?: Error;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Helper function to convert gRPC errors to Scrawn errors.
|
|
179
|
+
* Maps gRPC status codes to appropriate Scrawn error types.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
export declare function convertGrpcError(error: unknown, requestId?: string): ScrawnError;
|
|
184
|
+
/**
|
|
185
|
+
* Helper to check if an error is a Scrawn error.
|
|
186
|
+
*/
|
|
187
|
+
export declare function isScrawnError(error: unknown): error is ScrawnError;
|
|
188
|
+
/**
|
|
189
|
+
* Helper to check if an error is retryable.
|
|
190
|
+
*/
|
|
191
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
192
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,iDAAiD;IACjD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,sCAAsC;IACtC,SAAgB,SAAS,EAAE,OAAO,CAAC;IAEnC,qCAAqC;IACrC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpC,8CAA8C;IAC9C,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnC,+BAA+B;IAC/B,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE9C,qDAAqD;IACrD,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;gBAG5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,KAAK,CAAC;KACf;IAiBH;;OAEG;IAEH,MAAM;;;;;;;;;;CAYP;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,yBAA0B,SAAQ,WAAW;gBAEtD,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAA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