@oxyhq/contracts 0.9.0 → 0.10.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.
@@ -35,7 +35,7 @@
35
35
  * `require()`).
36
36
  */
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.deviceResolveResponseSchema = exports.deviceResolveRequestSchema = exports.loginResultSchema = exports.deviceTokenIssueResponseSchema = exports.tokenRefreshResponseSchema = exports.tokenRefreshRequestSchema = exports.authTokenBundleSchema = exports.deviceExchangeRequestSchema = exports.deviceBootFragmentSchema = exports.deviceBootReasonSchema = void 0;
38
+ exports.deviceResolveResponseSchema = exports.deviceResolveRequestSchema = exports.loginResultSchema = exports.deviceTokenIssueResponseSchema = exports.tokenRefreshResponseSchema = exports.tokenRefreshRequestSchema = exports.webSessionResultSchema = exports.authTokenBundleSchema = exports.deviceExchangeRequestSchema = exports.deviceBootFragmentSchema = exports.deviceBootReasonSchema = void 0;
39
39
  const zod_1 = require("zod");
40
40
  const userResponse_1 = require("./userResponse");
41
41
  /* -------------------------------------------------------------------------- */
@@ -51,17 +51,36 @@ const userResponse_1 = require("./userResponse");
51
51
  exports.deviceBootReasonSchema = zod_1.z.enum(['session', 'no_session', 'new_device']);
52
52
  /**
53
53
  * The `#oxy_boot=<json>` fragment `GET /auth/device/bootstrap` appends to the
54
- * `return_to` URL. Carries the CSRF `state` echo, the resolution `reason`, an
55
- * optional single-use exchange `code` (present iff `reason === 'session'`), and
56
- * the opaque `deviceToken`. NEVER carries tokens or a deviceId.
54
+ * `return_to` URL. Carries the CSRF `state` echo, the resolution `reason`, the
55
+ * opaque `deviceToken`, and ONLY on the `session` arm — the single-use
56
+ * exchange `code`. NEVER carries tokens or a deviceId.
57
+ *
58
+ * Discriminated on `reason` so the code↔reason coupling is enforced by the
59
+ * schema, not by the consumer: the `session` arm REQUIRES `code`, and the
60
+ * `no_session` / `new_device` arms omit it (a stray `code` on those arms is
61
+ * stripped). A `session` fragment WITHOUT a code therefore fails to parse and
62
+ * is treated as "no usable fragment" rather than half-processed.
57
63
  */
58
- exports.deviceBootFragmentSchema = zod_1.z.object({
64
+ const deviceBootFragmentBase = {
59
65
  v: zod_1.z.literal(1),
60
66
  state: zod_1.z.string().min(1).max(256),
61
- reason: exports.deviceBootReasonSchema,
62
- code: zod_1.z.string().min(20).max(128).optional(),
63
67
  deviceToken: zod_1.z.string().min(20).max(512),
64
- });
68
+ };
69
+ exports.deviceBootFragmentSchema = zod_1.z.discriminatedUnion('reason', [
70
+ zod_1.z.object({
71
+ ...deviceBootFragmentBase,
72
+ reason: zod_1.z.literal('session'),
73
+ code: zod_1.z.string().min(20).max(128),
74
+ }),
75
+ zod_1.z.object({
76
+ ...deviceBootFragmentBase,
77
+ reason: zod_1.z.literal('no_session'),
78
+ }),
79
+ zod_1.z.object({
80
+ ...deviceBootFragmentBase,
81
+ reason: zod_1.z.literal('new_device'),
82
+ }),
83
+ ]);
65
84
  /* -------------------------------------------------------------------------- */
66
85
  /* Boot-code exchange */
67
86
  /* -------------------------------------------------------------------------- */
@@ -76,6 +95,30 @@ exports.authTokenBundleSchema = zod_1.z.object({
76
95
  expiresAt: zod_1.z.string(),
77
96
  user: userResponse_1.userResponseSchema,
78
97
  });
98
+ // Internal (unexported) arm schemas — PLAIN `z.object` literals (no
99
+ // `z.ZodType<>` annotation) so `z.discriminatedUnion` can introspect the
100
+ // `reason` discriminator. The node10 `.d.ts`-degradation safety comes from the
101
+ // EXPORTED symbols instead: the public types are explicit interfaces
102
+ // (`WebSessionSession` / `WebSessionNoSession` / `WebSessionResult`) and the
103
+ // exported schema is annotated `z.ZodType<WebSessionResult>` below, so the
104
+ // emitted declaration states the shape literally rather than a degradable
105
+ // `z.infer<>` of the nested `session` object.
106
+ const webSessionSessionSchema = zod_1.z.object({
107
+ reason: zod_1.z.literal('session'),
108
+ session: exports.authTokenBundleSchema,
109
+ deviceToken: zod_1.z.string().min(1),
110
+ });
111
+ const webSessionNoSessionSchema = zod_1.z.object({
112
+ reason: zod_1.z.enum(['no_session', 'new_device']),
113
+ deviceToken: zod_1.z.string().min(1),
114
+ });
115
+ // Discriminated on `reason` — a true `discriminatedUnion` (not `z.union`): it
116
+ // dispatches on the discriminator instead of sequentially probing each arm,
117
+ // giving precise per-arm errors.
118
+ exports.webSessionResultSchema = zod_1.z.discriminatedUnion('reason', [
119
+ webSessionSessionSchema,
120
+ webSessionNoSessionSchema,
121
+ ]);
79
122
  /* -------------------------------------------------------------------------- */
80
123
  /* Refresh-token rotation (web + native, one implementation) */
81
124
  /* -------------------------------------------------------------------------- */
package/dist/cjs/index.js CHANGED
@@ -11,15 +11,13 @@
11
11
  * expo, no `require()` in the ESM build.
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.validationVoteResultSchema = exports.validationRequestSummarySchema = exports.validationOpenResultSchema = exports.validationOpenRequestSchema = exports.validationVerdictRecordSchema = exports.realLifeAttestationResultSchema = exports.realLifeAttestationRecordSchema = exports.signedPublicCardSchema = exports.publicCardSchema = exports.logPageResponseSchema = exports.chainHeadResponseSchema = exports.oxySignedRecordTypeSchema = exports.exportBundleSchema = exports.exportAttestationSchema = exports.authMethodsResponseSchema = exports.authMethodEntrySchema = exports.domainVerificationInstructionsSchema = exports.domainVerificationRequestSchema = exports.verifiedDomainSchema = exports.signedRecordEnvelopeSchema = exports.didDocumentSchema = exports.didServiceSchema = exports.verificationMethodSchema = exports.appAffinityEventsIngestSchema = exports.appAffinityEventSchema = exports.appAffinityEventTypeSchema = exports.appUserSignalIngestSchema = exports.appInterestInputSchema = exports.appEndorsementInputSchema = exports.recommendationResponseSchema = exports.recommendationItemSchema = exports.recommendationCountSchema = exports.recommendationRequestSchema = exports.recommendationSignalWeightsSchema = exports.recommendationBoostSchema = exports.recommendationExcludeTypeSchema = exports.fedcmTokenPayloadSchema = exports.sessionStatusSchema = exports.publicApplicationSchema = exports.applicationTypeSchema = exports.safeParseContract = exports.resolveUserId = exports.deviceSessionsResponseSchema = exports.deviceSessionAccountSchema = exports.currentUserResponseSchema = exports.refreshAllResponseSchema = exports.refreshAllAccountSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
15
- exports.deviceResolveResponseSchema = exports.deviceResolveRequestSchema = exports.loginResultSchema = exports.deviceTokenIssueResponseSchema = exports.tokenRefreshResponseSchema = exports.tokenRefreshRequestSchema = exports.authTokenBundleSchema = exports.deviceExchangeRequestSchema = exports.deviceBootFragmentSchema = exports.deviceBootReasonSchema = exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.credentialVerifyResultSchema = exports.credentialListResultSchema = exports.credentialIssueResultSchema = exports.verifiableCredentialResponseSchema = exports.credentialRecordSchema = exports.vouchResultSchema = exports.personhoodStatusResultSchema = exports.personhoodBreakdownSchema = exports.personhoodVouchRecordSchema = void 0;
14
+ exports.personhoodBreakdownSchema = exports.personhoodVouchRecordSchema = exports.validationVoteResultSchema = exports.validationRequestSummarySchema = exports.validationOpenResultSchema = exports.validationOpenRequestSchema = exports.validationVerdictRecordSchema = exports.realLifeAttestationResultSchema = exports.realLifeAttestationRecordSchema = exports.signedPublicCardSchema = exports.publicCardSchema = exports.logPageResponseSchema = exports.chainHeadResponseSchema = exports.oxySignedRecordTypeSchema = exports.exportBundleSchema = exports.exportAttestationSchema = exports.authMethodsResponseSchema = exports.authMethodEntrySchema = exports.domainVerificationInstructionsSchema = exports.domainVerificationRequestSchema = exports.verifiedDomainSchema = exports.signedRecordEnvelopeSchema = exports.didDocumentSchema = exports.didServiceSchema = exports.verificationMethodSchema = exports.appAffinityEventsIngestSchema = exports.appAffinityEventSchema = exports.appAffinityEventTypeSchema = exports.appUserSignalIngestSchema = exports.appInterestInputSchema = exports.appEndorsementInputSchema = exports.recommendationResponseSchema = exports.recommendationItemSchema = exports.recommendationCountSchema = exports.recommendationRequestSchema = exports.recommendationSignalWeightsSchema = exports.recommendationBoostSchema = exports.recommendationExcludeTypeSchema = exports.fedcmTokenPayloadSchema = exports.sessionStatusSchema = exports.publicApplicationSchema = exports.applicationTypeSchema = exports.safeParseContract = exports.resolveUserId = exports.deviceSessionsResponseSchema = exports.deviceSessionAccountSchema = exports.currentUserResponseSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
15
+ exports.deviceResolveResponseSchema = exports.deviceResolveRequestSchema = exports.loginResultSchema = exports.deviceTokenIssueResponseSchema = exports.tokenRefreshResponseSchema = exports.tokenRefreshRequestSchema = exports.webSessionResultSchema = exports.authTokenBundleSchema = exports.deviceExchangeRequestSchema = exports.deviceBootFragmentSchema = exports.deviceBootReasonSchema = exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.credentialVerifyResultSchema = exports.credentialListResultSchema = exports.credentialIssueResultSchema = exports.verifiableCredentialResponseSchema = exports.credentialRecordSchema = exports.vouchResultSchema = exports.personhoodStatusResultSchema = void 0;
16
16
  var userResponse_1 = require("./userResponse");
17
17
  // Schemas
18
18
  Object.defineProperty(exports, "userNameSchema", { enumerable: true, get: function () { return userResponse_1.userNameSchema; } });
19
19
  Object.defineProperty(exports, "userResponseSchema", { enumerable: true, get: function () { return userResponse_1.userResponseSchema; } });
20
20
  Object.defineProperty(exports, "userProfileUpdateSchema", { enumerable: true, get: function () { return userResponse_1.userProfileUpdateSchema; } });
21
- Object.defineProperty(exports, "refreshAllAccountSchema", { enumerable: true, get: function () { return userResponse_1.refreshAllAccountSchema; } });
22
- Object.defineProperty(exports, "refreshAllResponseSchema", { enumerable: true, get: function () { return userResponse_1.refreshAllResponseSchema; } });
23
21
  Object.defineProperty(exports, "currentUserResponseSchema", { enumerable: true, get: function () { return userResponse_1.currentUserResponseSchema; } });
24
22
  Object.defineProperty(exports, "deviceSessionAccountSchema", { enumerable: true, get: function () { return userResponse_1.deviceSessionAccountSchema; } });
25
23
  Object.defineProperty(exports, "deviceSessionsResponseSchema", { enumerable: true, get: function () { return userResponse_1.deviceSessionsResponseSchema; } });
@@ -107,6 +105,7 @@ Object.defineProperty(exports, "deviceBootReasonSchema", { enumerable: true, get
107
105
  Object.defineProperty(exports, "deviceBootFragmentSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceBootFragmentSchema; } });
108
106
  Object.defineProperty(exports, "deviceExchangeRequestSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceExchangeRequestSchema; } });
109
107
  Object.defineProperty(exports, "authTokenBundleSchema", { enumerable: true, get: function () { return deviceBoot_1.authTokenBundleSchema; } });
108
+ Object.defineProperty(exports, "webSessionResultSchema", { enumerable: true, get: function () { return deviceBoot_1.webSessionResultSchema; } });
110
109
  Object.defineProperty(exports, "tokenRefreshRequestSchema", { enumerable: true, get: function () { return deviceBoot_1.tokenRefreshRequestSchema; } });
111
110
  Object.defineProperty(exports, "tokenRefreshResponseSchema", { enumerable: true, get: function () { return deviceBoot_1.tokenRefreshResponseSchema; } });
112
111
  Object.defineProperty(exports, "deviceTokenIssueResponseSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceTokenIssueResponseSchema; } });
@@ -32,7 +32,7 @@
32
32
  * `require()`).
33
33
  */
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.deviceSessionsResponseSchema = exports.deviceSessionAccountSchema = exports.currentUserResponseSchema = exports.refreshAllResponseSchema = exports.refreshAllAccountSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
35
+ exports.deviceSessionsResponseSchema = exports.deviceSessionAccountSchema = exports.currentUserResponseSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
36
36
  exports.resolveUserId = resolveUserId;
37
37
  exports.safeParseContract = safeParseContract;
38
38
  const zod_1 = require("zod");
@@ -111,7 +111,6 @@ exports.userProfileUpdateSchema = zod_1.z
111
111
  phone: zod_1.z.string().optional(),
112
112
  address: zod_1.z.string().optional(),
113
113
  birthday: zod_1.z.string().optional(),
114
- location: zod_1.z.string().optional(),
115
114
  locations: zod_1.z.array(zod_1.z.unknown()).optional(),
116
115
  links: zod_1.z.array(zod_1.z.string()).optional(),
117
116
  linksMetadata: zod_1.z
@@ -137,28 +136,6 @@ exports.userProfileUpdateSchema = zod_1.z
137
136
  function resolveUserId(user) {
138
137
  return user.id ?? user._id;
139
138
  }
140
- /**
141
- * One rotated account entry from `POST /auth/refresh-all`.
142
- *
143
- * `authuser` is the device-local slot index (`0..N-1`). `user` is the canonical
144
- * {@link userResponseSchema} shape (the handler projects a whitelist and runs it
145
- * through `formatUserResponse`).
146
- */
147
- exports.refreshAllAccountSchema = zod_1.z.object({
148
- authuser: zod_1.z.number().int().nonnegative(),
149
- accessToken: zod_1.z.string(),
150
- expiresAt: zod_1.z.string(),
151
- sessionId: zod_1.z.string(),
152
- user: exports.userResponseSchema,
153
- });
154
- /**
155
- * Wire shape of `POST /auth/refresh-all`: every valid device-local account,
156
- * sorted by `authuser` ascending. An empty `accounts` array means "no signed-in
157
- * accounts on this device" — the IdP must show the sign-in form.
158
- */
159
- exports.refreshAllResponseSchema = zod_1.z.object({
160
- accounts: zod_1.z.array(exports.refreshAllAccountSchema),
161
- });
162
139
  /**
163
140
  * Wire shape of `GET /users/me` — the API success envelope (`{ data: <user> }`)
164
141
  * wrapping the current-user DTO. Some older producers use `_id` instead of