@capxul/sdk 0.1.0-alpha.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.
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ // src/errors.ts
4
+ var CapxulError = class extends Error {
5
+ code;
6
+ details;
7
+ operationId;
8
+ correlationId;
9
+ retryable;
10
+ constructor(init) {
11
+ super(
12
+ init.message,
13
+ init.cause !== void 0 ? { cause: init.cause } : void 0
14
+ );
15
+ this.name = "CapxulError";
16
+ this.code = init.code;
17
+ this.details = init.details;
18
+ this.operationId = init.operationId;
19
+ this.correlationId = init.correlationId;
20
+ this.retryable = init.retryable;
21
+ }
22
+ };
23
+ function notImplemented(method) {
24
+ return new CapxulError({
25
+ code: "NOT_IMPLEMENTED",
26
+ message: `${method} is not yet implemented in @capxul/sdk (Slice C scaffold).`
27
+ });
28
+ }
29
+ function stub(method) {
30
+ return [notImplemented(method), null];
31
+ }
32
+
33
+ exports.CapxulError = CapxulError;
34
+ exports.notImplemented = notImplemented;
35
+ exports.stub = stub;
@@ -0,0 +1,55 @@
1
+ import { CapxulErrorCode, CapxulErrorDetails, OperationId, CorrelationId } from '@repo/platform-kernel';
2
+
3
+ /**
4
+ * Unified error class surfaced by every SDK method.
5
+ *
6
+ * Parameterized on `Codes` so individual method signatures can narrow
7
+ * to the subset of `CapxulErrorCode` they actually produce (per
8
+ * CANON.md §4.39 + §4.44 + sdk-surface.md §3a). The default
9
+ * `Codes = CapxulErrorCode` is the global catalog from
10
+ * `@repo/platform-kernel` — 34 values aligned with the wire
11
+ * `ErrorEnvelope.error.code` enum.
12
+ */
13
+ declare class CapxulError<Codes extends CapxulErrorCode = CapxulErrorCode> extends Error {
14
+ readonly code: Codes;
15
+ readonly details?: CapxulErrorDetails;
16
+ readonly operationId?: OperationId;
17
+ readonly correlationId?: CorrelationId;
18
+ readonly retryable?: boolean;
19
+ constructor(init: {
20
+ code: Codes;
21
+ message: string;
22
+ cause?: unknown;
23
+ details?: CapxulErrorDetails;
24
+ operationId?: OperationId;
25
+ correlationId?: CorrelationId;
26
+ retryable?: boolean;
27
+ });
28
+ }
29
+ /**
30
+ * Direct tuple-return shape per CANON.md §4.39: every SDK mutation or
31
+ * read returns `[null, value]` on success or `[CapxulError<Codes>, null]`
32
+ * on failure. The tuple is `readonly` so callers can destructure
33
+ * without worrying about mutation.
34
+ */
35
+ type CapxulResult<T, Codes extends CapxulErrorCode = CapxulErrorCode> = readonly [null, T] | readonly [CapxulError<Codes>, null];
36
+ /**
37
+ * Internal helper. Returns a concrete `CapxulError<"NOT_IMPLEMENTED">`
38
+ * suitable for `throw` from non-tuple surfaces (e.g. `verifyWebhook`).
39
+ */
40
+ declare function notImplemented(method: string): CapxulError<"NOT_IMPLEMENTED">;
41
+ /**
42
+ * Scaffold-only stub helper for every tuple-return SDK method. Returns
43
+ * the failed tuple `[CapxulError<Codes>, null]` carrying a
44
+ * `NOT_IMPLEMENTED` error.
45
+ *
46
+ * The `as CapxulError<Codes>` cast is intentionally unsound: runtime
47
+ * `code` is `"NOT_IMPLEMENTED"` even though the method's narrowed
48
+ * `Codes` union may not list it. This goes away in Slice F when real
49
+ * HTTP bodies replace every call site. Until then, callers shouldn't
50
+ * switch on the runtime `code` inside tests — the scaffold's contract
51
+ * is strictly type-level.
52
+ */
53
+ declare function stub<T, Codes extends CapxulErrorCode = CapxulErrorCode>(method: string): CapxulResult<T, Codes>;
54
+
55
+ export { CapxulError, type CapxulResult, notImplemented, stub };
@@ -0,0 +1,55 @@
1
+ import { CapxulErrorCode, CapxulErrorDetails, OperationId, CorrelationId } from '@repo/platform-kernel';
2
+
3
+ /**
4
+ * Unified error class surfaced by every SDK method.
5
+ *
6
+ * Parameterized on `Codes` so individual method signatures can narrow
7
+ * to the subset of `CapxulErrorCode` they actually produce (per
8
+ * CANON.md §4.39 + §4.44 + sdk-surface.md §3a). The default
9
+ * `Codes = CapxulErrorCode` is the global catalog from
10
+ * `@repo/platform-kernel` — 34 values aligned with the wire
11
+ * `ErrorEnvelope.error.code` enum.
12
+ */
13
+ declare class CapxulError<Codes extends CapxulErrorCode = CapxulErrorCode> extends Error {
14
+ readonly code: Codes;
15
+ readonly details?: CapxulErrorDetails;
16
+ readonly operationId?: OperationId;
17
+ readonly correlationId?: CorrelationId;
18
+ readonly retryable?: boolean;
19
+ constructor(init: {
20
+ code: Codes;
21
+ message: string;
22
+ cause?: unknown;
23
+ details?: CapxulErrorDetails;
24
+ operationId?: OperationId;
25
+ correlationId?: CorrelationId;
26
+ retryable?: boolean;
27
+ });
28
+ }
29
+ /**
30
+ * Direct tuple-return shape per CANON.md §4.39: every SDK mutation or
31
+ * read returns `[null, value]` on success or `[CapxulError<Codes>, null]`
32
+ * on failure. The tuple is `readonly` so callers can destructure
33
+ * without worrying about mutation.
34
+ */
35
+ type CapxulResult<T, Codes extends CapxulErrorCode = CapxulErrorCode> = readonly [null, T] | readonly [CapxulError<Codes>, null];
36
+ /**
37
+ * Internal helper. Returns a concrete `CapxulError<"NOT_IMPLEMENTED">`
38
+ * suitable for `throw` from non-tuple surfaces (e.g. `verifyWebhook`).
39
+ */
40
+ declare function notImplemented(method: string): CapxulError<"NOT_IMPLEMENTED">;
41
+ /**
42
+ * Scaffold-only stub helper for every tuple-return SDK method. Returns
43
+ * the failed tuple `[CapxulError<Codes>, null]` carrying a
44
+ * `NOT_IMPLEMENTED` error.
45
+ *
46
+ * The `as CapxulError<Codes>` cast is intentionally unsound: runtime
47
+ * `code` is `"NOT_IMPLEMENTED"` even though the method's narrowed
48
+ * `Codes` union may not list it. This goes away in Slice F when real
49
+ * HTTP bodies replace every call site. Until then, callers shouldn't
50
+ * switch on the runtime `code` inside tests — the scaffold's contract
51
+ * is strictly type-level.
52
+ */
53
+ declare function stub<T, Codes extends CapxulErrorCode = CapxulErrorCode>(method: string): CapxulResult<T, Codes>;
54
+
55
+ export { CapxulError, type CapxulResult, notImplemented, stub };
package/dist/errors.js ADDED
@@ -0,0 +1,31 @@
1
+ // src/errors.ts
2
+ var CapxulError = class extends Error {
3
+ code;
4
+ details;
5
+ operationId;
6
+ correlationId;
7
+ retryable;
8
+ constructor(init) {
9
+ super(
10
+ init.message,
11
+ init.cause !== void 0 ? { cause: init.cause } : void 0
12
+ );
13
+ this.name = "CapxulError";
14
+ this.code = init.code;
15
+ this.details = init.details;
16
+ this.operationId = init.operationId;
17
+ this.correlationId = init.correlationId;
18
+ this.retryable = init.retryable;
19
+ }
20
+ };
21
+ function notImplemented(method) {
22
+ return new CapxulError({
23
+ code: "NOT_IMPLEMENTED",
24
+ message: `${method} is not yet implemented in @capxul/sdk (Slice C scaffold).`
25
+ });
26
+ }
27
+ function stub(method) {
28
+ return [notImplemented(method), null];
29
+ }
30
+
31
+ export { CapxulError, notImplemented, stub };