@smartcrab/contracts-public 0.1.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.
Files changed (54) hide show
  1. package/LICENSE +202 -0
  2. package/dist/association-files.d.ts +46 -0
  3. package/dist/association-files.js +32 -0
  4. package/dist/config.d.ts +57 -0
  5. package/dist/config.js +38 -0
  6. package/dist/email.d.ts +55 -0
  7. package/dist/email.js +39 -0
  8. package/dist/index.d.ts +23 -0
  9. package/dist/index.js +23 -0
  10. package/dist/me.d.ts +297 -0
  11. package/dist/me.js +140 -0
  12. package/dist/oidc.d.ts +239 -0
  13. package/dist/oidc.js +230 -0
  14. package/dist/outcome.d.ts +19 -0
  15. package/dist/outcome.js +2 -0
  16. package/dist/passkeys.d.ts +257 -0
  17. package/dist/passkeys.js +162 -0
  18. package/dist/primitives.d.ts +60 -0
  19. package/dist/primitives.js +52 -0
  20. package/dist/redirect-uri.d.ts +25 -0
  21. package/dist/redirect-uri.js +39 -0
  22. package/dist/scopes.d.ts +30 -0
  23. package/dist/scopes.js +46 -0
  24. package/dist/social.d.ts +44 -0
  25. package/dist/social.js +35 -0
  26. package/dist/transaction-status.d.ts +53 -0
  27. package/dist/transaction-status.js +37 -0
  28. package/dist/transactions.d.ts +144 -0
  29. package/dist/transactions.js +103 -0
  30. package/package.json +43 -0
  31. package/src/association-files.test.ts +71 -0
  32. package/src/association-files.ts +46 -0
  33. package/src/config.test.ts +66 -0
  34. package/src/config.ts +62 -0
  35. package/src/email.test.ts +40 -0
  36. package/src/email.ts +50 -0
  37. package/src/index.ts +23 -0
  38. package/src/me.test.ts +116 -0
  39. package/src/me.ts +223 -0
  40. package/src/oidc.test.ts +224 -0
  41. package/src/oidc.ts +296 -0
  42. package/src/outcome.ts +17 -0
  43. package/src/passkeys.test.ts +80 -0
  44. package/src/passkeys.ts +218 -0
  45. package/src/primitives.ts +79 -0
  46. package/src/redirect-uri.test.ts +118 -0
  47. package/src/redirect-uri.ts +86 -0
  48. package/src/scopes.test.ts +51 -0
  49. package/src/scopes.ts +63 -0
  50. package/src/social.test.ts +34 -0
  51. package/src/social.ts +43 -0
  52. package/src/transaction-status.ts +44 -0
  53. package/src/transactions.test.ts +153 -0
  54. package/src/transactions.ts +129 -0
@@ -0,0 +1,129 @@
1
+ import { authMethodSchema } from "@smartcrab/tenant-context";
2
+ import { z } from "zod";
3
+ import {
4
+ authorizationCodeSchema,
5
+ clientIdSchema,
6
+ codeChallengeSchema,
7
+ isoDateTimeSchema,
8
+ opaqueClientValueSchema,
9
+ redirectUriSchema,
10
+ resourceListSchema,
11
+ transactionIdSchema,
12
+ } from "./primitives.js";
13
+ import { scopeStringSchema } from "./scopes.js";
14
+ import { socialProviderSchema } from "./social.js";
15
+ import { transactionAuthMethodSchema, transactionStatusSchema } from "./transaction-status.js";
16
+
17
+ /**
18
+ * `POST /v1/auth/transactions` (design.md §16.1, exact example):
19
+ *
20
+ * ```json
21
+ * {
22
+ * "client_id": "cli_xxx",
23
+ * "redirect_uri": "com.customer.app:/oauth/callback",
24
+ * "code_challenge": "...",
25
+ * "code_challenge_method": "S256",
26
+ * "state": "...",
27
+ * "nonce": "...",
28
+ * "scope": "openid profile email offline_access",
29
+ * "resource": ["https://api.customer.example"],
30
+ * "response_mode": "native_return"
31
+ * }
32
+ * ```
33
+ */
34
+ export const RESPONSE_MODES = ["redirect", "native_return"] as const;
35
+ export const responseModeSchema = z.enum(RESPONSE_MODES);
36
+ export type ResponseMode = (typeof RESPONSE_MODES)[number];
37
+
38
+ /** `plain` is rejected: only `S256` is a valid literal (design.md §15.3). */
39
+ export const transactionCodeChallengeMethodSchema = z.literal("S256");
40
+
41
+ export const transactionCreateRequestSchema = z.strictObject({
42
+ client_id: clientIdSchema,
43
+ redirect_uri: redirectUriSchema,
44
+ code_challenge: codeChallengeSchema,
45
+ code_challenge_method: transactionCodeChallengeMethodSchema,
46
+ state: opaqueClientValueSchema,
47
+ nonce: opaqueClientValueSchema.optional(),
48
+ scope: scopeStringSchema,
49
+ resource: resourceListSchema.optional(),
50
+ response_mode: responseModeSchema.optional(),
51
+ });
52
+ export type TransactionCreateRequest = z.infer<typeof transactionCreateRequestSchema>;
53
+
54
+ /**
55
+ * ```json
56
+ * {
57
+ * "transaction_id": "txn_xxx",
58
+ * "expires_at": "2026-08-02T08:10:00Z",
59
+ * "available_methods": ["passkey", "google", "apple", "email_otp"]
60
+ * }
61
+ * ```
62
+ */
63
+ export const transactionCreateResponseSchema = z.strictObject({
64
+ transaction_id: transactionIdSchema,
65
+ expires_at: isoDateTimeSchema,
66
+ available_methods: z.array(authMethodSchema),
67
+ });
68
+ export type TransactionCreateResponse = z.infer<typeof transactionCreateResponseSchema>;
69
+
70
+ /**
71
+ * `GET /v1/auth/transactions/:transactionId` — status polling for Hosted UI /
72
+ * React Native (design.md §16.2 lists the route; §14.2 defines the status
73
+ * machine this projects).
74
+ */
75
+ export const transactionGetResponseSchema = z.strictObject({
76
+ transaction_id: transactionIdSchema,
77
+ status: transactionStatusSchema,
78
+ expires_at: isoDateTimeSchema,
79
+ available_methods: z.array(authMethodSchema),
80
+ /** Present once a verify step has advanced the transaction to `authenticated`. */
81
+ method: transactionAuthMethodSchema.optional(),
82
+ /** §20.5 exposes only which provider awaits re-authentication, never its subject/email/user. */
83
+ pending_link: z
84
+ .strictObject({
85
+ provider: socialProviderSchema,
86
+ })
87
+ .nullable(),
88
+ });
89
+ export type TransactionGetResponse = z.infer<typeof transactionGetResponseSchema>;
90
+
91
+ /** `POST /v1/auth/transactions/:transactionId/cancel` — no request body. */
92
+ export const transactionCancelRequestSchema = z.strictObject({});
93
+ export type TransactionCancelRequest = z.infer<typeof transactionCancelRequestSchema>;
94
+
95
+ /**
96
+ * A cancelled transaction moves to `failed` (design.md §14.2's status
97
+ * machine has no separate `canceled` state); the client only needs to know
98
+ * it can no longer be resumed.
99
+ */
100
+ export const transactionCancelResponseSchema = z.strictObject({
101
+ transaction_id: transactionIdSchema,
102
+ status: z.literal("failed"),
103
+ });
104
+ export type TransactionCancelResponse = z.infer<typeof transactionCancelResponseSchema>;
105
+
106
+ /**
107
+ * `POST /v1/auth/transactions/:transactionId/complete` (design.md §16.3,
108
+ * exact example):
109
+ *
110
+ * ```json
111
+ * {
112
+ * "authorization_code": "ac_xxx",
113
+ * "state": "original-state",
114
+ * "redirect_uri": "com.customer.app:/oauth/callback"
115
+ * }
116
+ * ```
117
+ *
118
+ * No request body: the transaction must already be `authenticated` via one
119
+ * of the verify endpoints.
120
+ */
121
+ export const transactionCompleteRequestSchema = z.strictObject({});
122
+ export type TransactionCompleteRequest = z.infer<typeof transactionCompleteRequestSchema>;
123
+
124
+ export const transactionCompleteResponseSchema = z.strictObject({
125
+ authorization_code: authorizationCodeSchema,
126
+ state: opaqueClientValueSchema,
127
+ redirect_uri: redirectUriSchema,
128
+ });
129
+ export type TransactionCompleteResponse = z.infer<typeof transactionCompleteResponseSchema>;