@productcraft/heimdall 0.1.0 → 0.2.1
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/README.md +38 -20
- package/dist/index.cjs +69 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -65
- package/dist/index.d.ts +123 -65
- package/dist/index.js +69 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1260,13 +1260,13 @@ type SetScopesDto = {
|
|
|
1260
1260
|
|
|
1261
1261
|
type AppControllerListInvitesQueryParams = {
|
|
1262
1262
|
/**
|
|
1263
|
-
* @type string
|
|
1263
|
+
* @type string | undefined
|
|
1264
1264
|
*/
|
|
1265
|
-
limit
|
|
1265
|
+
limit?: string;
|
|
1266
1266
|
/**
|
|
1267
|
-
* @type string
|
|
1267
|
+
* @type string | undefined
|
|
1268
1268
|
*/
|
|
1269
|
-
cursor
|
|
1269
|
+
cursor?: string;
|
|
1270
1270
|
};
|
|
1271
1271
|
|
|
1272
1272
|
/**
|
|
@@ -1276,13 +1276,13 @@ type AppControllerListInvitesQueryParams = {
|
|
|
1276
1276
|
|
|
1277
1277
|
type AppControllerListMembersQueryParams = {
|
|
1278
1278
|
/**
|
|
1279
|
-
* @type string
|
|
1279
|
+
* @type string | undefined
|
|
1280
1280
|
*/
|
|
1281
|
-
limit
|
|
1281
|
+
limit?: string;
|
|
1282
1282
|
/**
|
|
1283
|
-
* @type string
|
|
1283
|
+
* @type string | undefined
|
|
1284
1284
|
*/
|
|
1285
|
-
cursor
|
|
1285
|
+
cursor?: string;
|
|
1286
1286
|
};
|
|
1287
1287
|
|
|
1288
1288
|
/**
|
|
@@ -1292,21 +1292,21 @@ type AppControllerListMembersQueryParams = {
|
|
|
1292
1292
|
|
|
1293
1293
|
type EndUserControllerListEndUsersQueryParams = {
|
|
1294
1294
|
/**
|
|
1295
|
-
* @type string
|
|
1295
|
+
* @type string | undefined
|
|
1296
1296
|
*/
|
|
1297
|
-
limit
|
|
1297
|
+
limit?: string;
|
|
1298
1298
|
/**
|
|
1299
|
-
* @type string
|
|
1299
|
+
* @type string | undefined
|
|
1300
1300
|
*/
|
|
1301
|
-
cursor
|
|
1301
|
+
cursor?: string;
|
|
1302
1302
|
/**
|
|
1303
|
-
* @type string
|
|
1303
|
+
* @type string | undefined
|
|
1304
1304
|
*/
|
|
1305
|
-
status
|
|
1305
|
+
status?: string;
|
|
1306
1306
|
/**
|
|
1307
|
-
* @type string
|
|
1307
|
+
* @type string | undefined
|
|
1308
1308
|
*/
|
|
1309
|
-
search
|
|
1309
|
+
search?: string;
|
|
1310
1310
|
};
|
|
1311
1311
|
|
|
1312
1312
|
/**
|
|
@@ -1316,21 +1316,21 @@ type EndUserControllerListEndUsersQueryParams = {
|
|
|
1316
1316
|
|
|
1317
1317
|
type AppAuditControllerGetAuditLogsQueryParams = {
|
|
1318
1318
|
/**
|
|
1319
|
-
* @type string
|
|
1319
|
+
* @type string | undefined
|
|
1320
1320
|
*/
|
|
1321
|
-
limit
|
|
1321
|
+
limit?: string;
|
|
1322
1322
|
/**
|
|
1323
|
-
* @type string
|
|
1323
|
+
* @type string | undefined
|
|
1324
1324
|
*/
|
|
1325
|
-
cursor
|
|
1325
|
+
cursor?: string;
|
|
1326
1326
|
/**
|
|
1327
|
-
* @type string
|
|
1327
|
+
* @type string | undefined
|
|
1328
1328
|
*/
|
|
1329
|
-
action
|
|
1329
|
+
action?: string;
|
|
1330
1330
|
/**
|
|
1331
|
-
* @type string
|
|
1331
|
+
* @type string | undefined
|
|
1332
1332
|
*/
|
|
1333
|
-
actor_id
|
|
1333
|
+
actor_id?: string;
|
|
1334
1334
|
};
|
|
1335
1335
|
|
|
1336
1336
|
/**
|
|
@@ -1340,13 +1340,13 @@ type AppAuditControllerGetAuditLogsQueryParams = {
|
|
|
1340
1340
|
|
|
1341
1341
|
type M2MControllerListClientsQueryParams = {
|
|
1342
1342
|
/**
|
|
1343
|
-
* @type string
|
|
1343
|
+
* @type string | undefined
|
|
1344
1344
|
*/
|
|
1345
|
-
limit
|
|
1345
|
+
limit?: string;
|
|
1346
1346
|
/**
|
|
1347
|
-
* @type string
|
|
1347
|
+
* @type string | undefined
|
|
1348
1348
|
*/
|
|
1349
|
-
cursor
|
|
1349
|
+
cursor?: string;
|
|
1350
1350
|
};
|
|
1351
1351
|
|
|
1352
1352
|
/**
|
|
@@ -1356,13 +1356,13 @@ type M2MControllerListClientsQueryParams = {
|
|
|
1356
1356
|
|
|
1357
1357
|
type RoleControllerListRolesQueryParams = {
|
|
1358
1358
|
/**
|
|
1359
|
-
* @type string
|
|
1359
|
+
* @type string | undefined
|
|
1360
1360
|
*/
|
|
1361
|
-
limit
|
|
1361
|
+
limit?: string;
|
|
1362
1362
|
/**
|
|
1363
|
-
* @type string
|
|
1363
|
+
* @type string | undefined
|
|
1364
1364
|
*/
|
|
1365
|
-
cursor
|
|
1365
|
+
cursor?: string;
|
|
1366
1366
|
};
|
|
1367
1367
|
|
|
1368
1368
|
declare class AppScope {
|
|
@@ -1477,6 +1477,11 @@ type AuthorizeBatchResultDto = {
|
|
|
1477
1477
|
* @type boolean
|
|
1478
1478
|
*/
|
|
1479
1479
|
authorized: boolean;
|
|
1480
|
+
/**
|
|
1481
|
+
* @description Caller-supplied id from the corresponding check entry. Echoed back so callers can correlate results to inputs without relying on array order.
|
|
1482
|
+
* @type string | undefined
|
|
1483
|
+
*/
|
|
1484
|
+
id?: string;
|
|
1480
1485
|
/**
|
|
1481
1486
|
* @type array
|
|
1482
1487
|
*/
|
|
@@ -1798,10 +1803,10 @@ type UpdateMeDto = {
|
|
|
1798
1803
|
*/
|
|
1799
1804
|
type VerifyBody = {
|
|
1800
1805
|
/**
|
|
1801
|
-
* @description EndUser or M2M JWT to verify against the app JWKS.
|
|
1802
|
-
* @type string
|
|
1806
|
+
* @description EndUser or M2M JWT to verify against the app JWKS. Optional — if omitted, the token is read from the `Authorization: Bearer <jwt>` header instead.
|
|
1807
|
+
* @type string | undefined
|
|
1803
1808
|
*/
|
|
1804
|
-
token
|
|
1809
|
+
token?: string;
|
|
1805
1810
|
};
|
|
1806
1811
|
|
|
1807
1812
|
/**
|
|
@@ -1820,10 +1825,10 @@ type AuthorizeBody = {
|
|
|
1820
1825
|
*/
|
|
1821
1826
|
permissions?: string[];
|
|
1822
1827
|
/**
|
|
1823
|
-
* @description JWT to verify and authorize.
|
|
1824
|
-
* @type string
|
|
1828
|
+
* @description JWT to verify and authorize. Optional — if omitted, the token is read from the `Authorization: Bearer <jwt>` header.
|
|
1829
|
+
* @type string | undefined
|
|
1825
1830
|
*/
|
|
1826
|
-
token
|
|
1831
|
+
token?: string;
|
|
1827
1832
|
};
|
|
1828
1833
|
|
|
1829
1834
|
/**
|
|
@@ -1832,10 +1837,20 @@ type AuthorizeBody = {
|
|
|
1832
1837
|
*/
|
|
1833
1838
|
type AuthorizeBatchEntry = {
|
|
1834
1839
|
/**
|
|
1835
|
-
* @description
|
|
1836
|
-
* @type
|
|
1840
|
+
* @description Caller-chosen correlation id for this check. Echoed back on the matching result so the caller can map results to inputs without relying on array order.
|
|
1841
|
+
* @type string | undefined
|
|
1837
1842
|
*/
|
|
1838
|
-
|
|
1843
|
+
id?: string;
|
|
1844
|
+
/**
|
|
1845
|
+
* @description Single permission to check, e.g. \'invoice.read\'. Use this OR `permissions`.
|
|
1846
|
+
* @type string | undefined
|
|
1847
|
+
*/
|
|
1848
|
+
permission?: string;
|
|
1849
|
+
/**
|
|
1850
|
+
* @description Multiple permissions; ALL must be held for this check to pass.
|
|
1851
|
+
* @type array | undefined
|
|
1852
|
+
*/
|
|
1853
|
+
permissions?: string[];
|
|
1839
1854
|
};
|
|
1840
1855
|
|
|
1841
1856
|
/**
|
|
@@ -1845,15 +1860,15 @@ type AuthorizeBatchEntry = {
|
|
|
1845
1860
|
|
|
1846
1861
|
type AuthorizeBatchBody = {
|
|
1847
1862
|
/**
|
|
1848
|
-
* @description List of checks. Each returns { authorized, missing_permissions }.
|
|
1863
|
+
* @description List of checks. Each returns { id?, authorized, missing_permissions }.
|
|
1849
1864
|
* @type array
|
|
1850
1865
|
*/
|
|
1851
1866
|
checks: AuthorizeBatchEntry[];
|
|
1852
1867
|
/**
|
|
1853
|
-
* @description JWT to verify and authorize against each check.
|
|
1854
|
-
* @type string
|
|
1868
|
+
* @description JWT to verify and authorize against each check. Optional — if omitted, the token is read from the `Authorization: Bearer <jwt>` header.
|
|
1869
|
+
* @type string | undefined
|
|
1855
1870
|
*/
|
|
1856
|
-
token
|
|
1871
|
+
token?: string;
|
|
1857
1872
|
};
|
|
1858
1873
|
|
|
1859
1874
|
/**
|
|
@@ -2077,6 +2092,15 @@ interface VerifyOptions {
|
|
|
2077
2092
|
*/
|
|
2078
2093
|
declare function verifyHeimdallToken(token: string, getKey: HeimdallGetKeyFn, opts?: VerifyOptions): Promise<HeimdallClaims>;
|
|
2079
2094
|
|
|
2095
|
+
/**
|
|
2096
|
+
* Legacy `iss` claim Heimdall Consumer-API tokens used to be minted
|
|
2097
|
+
* with. Kept exported so consumers verifying tokens issued before the
|
|
2098
|
+
* 2026-05-24 per-app-issuer migration can still match `iss` while a
|
|
2099
|
+
* deployment cycles to fresh tokens. New tokens carry the per-app
|
|
2100
|
+
* issuer URL — `${baseUrl}/${appSlug}` — accessible via
|
|
2101
|
+
* `scope.expectedIssuer`.
|
|
2102
|
+
*/
|
|
2103
|
+
declare const HEIMDALL_LEGACY_ISSUER = "heimdall";
|
|
2080
2104
|
interface ConsumerScopeInternals {
|
|
2081
2105
|
client: Client;
|
|
2082
2106
|
baseUrl: string;
|
|
@@ -2086,15 +2110,38 @@ interface ConsumerScopeInternals {
|
|
|
2086
2110
|
declare class ConsumerScope {
|
|
2087
2111
|
/** The appSlug bound to this scope. */
|
|
2088
2112
|
readonly appSlug: string;
|
|
2089
|
-
/**
|
|
2113
|
+
/**
|
|
2114
|
+
* Issuer the Heimdall Consumer API stamps on every token for this
|
|
2115
|
+
* app — the public Heimdall API base joined with the app slug
|
|
2116
|
+
* (e.g. `https://api.heimdall.productcraft.co/acme`). Pin it in
|
|
2117
|
+
* your local verifier so a token minted for another app on the
|
|
2118
|
+
* platform cannot pass.
|
|
2119
|
+
*
|
|
2120
|
+
* `scope.verifyToken` already enforces this for you. Pass it as a
|
|
2121
|
+
* second-position issuer if you're wiring `jose.jwtVerify`,
|
|
2122
|
+
* `passport-jwt`, or PyJWT yourself.
|
|
2123
|
+
*/
|
|
2090
2124
|
readonly expectedIssuer: string;
|
|
2091
|
-
/**
|
|
2092
|
-
|
|
2125
|
+
/**
|
|
2126
|
+
* Audience the Consumer API stamps on every token for this app —
|
|
2127
|
+
* literally the app slug (e.g. `"acme"`). Pin it in your verifier
|
|
2128
|
+
* the same way as `expectedIssuer`. `scope.verifyToken` enforces
|
|
2129
|
+
* it by default.
|
|
2130
|
+
*/
|
|
2131
|
+
readonly expectedAudience: string;
|
|
2132
|
+
/**
|
|
2133
|
+
* Both accepted issuer strings (`expectedIssuer` + the legacy
|
|
2134
|
+
* `'heimdall'` literal). `verifyToken` passes this to jose so tokens
|
|
2135
|
+
* minted before the 2026-05-24 per-app-issuer migration keep
|
|
2136
|
+
* verifying alongside fresh ones — useful for the ~1-hour transition
|
|
2137
|
+
* window per access-token TTL, and the longer session TTL on
|
|
2138
|
+
* refresh tokens.
|
|
2139
|
+
*/
|
|
2140
|
+
readonly acceptedIssuers: readonly string[];
|
|
2093
2141
|
/** jose-compatible JWKS resolver. Drop into `jose.jwtVerify`, passport-jwt, etc. */
|
|
2094
2142
|
readonly jwks: JwksCache;
|
|
2095
2143
|
private readonly client;
|
|
2096
2144
|
constructor(appSlug: string, internals: ConsumerScopeInternals, opts?: {
|
|
2097
|
-
audience?: string;
|
|
2098
2145
|
jwksTtlMs?: number;
|
|
2099
2146
|
});
|
|
2100
2147
|
/**
|
|
@@ -2103,7 +2150,17 @@ declare class ConsumerScope {
|
|
|
2103
2150
|
* upstream; remove once the spec is fixed.
|
|
2104
2151
|
*/
|
|
2105
2152
|
private callDirect;
|
|
2106
|
-
/**
|
|
2153
|
+
/**
|
|
2154
|
+
* Verify a Heimdall-issued JWT against this app's JWKS.
|
|
2155
|
+
*
|
|
2156
|
+
* Checks the signature, expiry, `iss`, and `aud`. Accepts both the
|
|
2157
|
+
* per-app issuer URL (`expectedIssuer`) and the legacy `'heimdall'`
|
|
2158
|
+
* literal during the issuer-migration transition window — callers
|
|
2159
|
+
* who want to refuse legacy tokens can override with
|
|
2160
|
+
* `{ issuer: scope.expectedIssuer }`. Audience defaults to the app
|
|
2161
|
+
* slug (`expectedAudience`); pass `{ audience: false }` (in an
|
|
2162
|
+
* options override) to skip the audience check entirely.
|
|
2163
|
+
*/
|
|
2107
2164
|
verifyToken(token: string, opts?: VerifyOptions): Promise<HeimdallClaims>;
|
|
2108
2165
|
readonly auth: {
|
|
2109
2166
|
signin: (data: ConsumerSigninDto) => Promise<ConsumerAuthControllerSignin200>;
|
|
@@ -2170,6 +2227,13 @@ declare class ConsumerScope {
|
|
|
2170
2227
|
deleteAccount: () => Promise<void>;
|
|
2171
2228
|
};
|
|
2172
2229
|
readonly verify: {
|
|
2230
|
+
/**
|
|
2231
|
+
* The kubb-generated client makes `headers.authorization` a required
|
|
2232
|
+
* arg because the server controllers accept the bearer as a fallback
|
|
2233
|
+
* to `body.token`. We stub an empty string here — the HTTP client's
|
|
2234
|
+
* auth middleware overrides whatever's passed with the configured
|
|
2235
|
+
* credential (`PCAuth.apiKey` / `bearer` / `cookie`).
|
|
2236
|
+
*/
|
|
2173
2237
|
verify: (data: VerifyBody) => Promise<VerifyResponseDto>;
|
|
2174
2238
|
authorize: (data: AuthorizeBody) => Promise<AuthorizeResponseDto>;
|
|
2175
2239
|
authorizeBatch: (data: AuthorizeBatchBody) => Promise<AuthorizeBatchResponseDto>;
|
|
@@ -2224,17 +2288,17 @@ type AcceptInviteDto = {
|
|
|
2224
2288
|
|
|
2225
2289
|
type AppControllerListMyAppsQueryParams = {
|
|
2226
2290
|
/**
|
|
2227
|
-
* @type string
|
|
2291
|
+
* @type string | undefined
|
|
2228
2292
|
*/
|
|
2229
|
-
limit
|
|
2293
|
+
limit?: string;
|
|
2230
2294
|
/**
|
|
2231
|
-
* @type string
|
|
2295
|
+
* @type string | undefined
|
|
2232
2296
|
*/
|
|
2233
|
-
cursor
|
|
2297
|
+
cursor?: string;
|
|
2234
2298
|
/**
|
|
2235
|
-
* @type string
|
|
2299
|
+
* @type string | undefined
|
|
2236
2300
|
*/
|
|
2237
|
-
workspace_id
|
|
2301
|
+
workspace_id?: string;
|
|
2238
2302
|
};
|
|
2239
2303
|
|
|
2240
2304
|
/**
|
|
@@ -2244,9 +2308,9 @@ type AppControllerListMyAppsQueryParams = {
|
|
|
2244
2308
|
|
|
2245
2309
|
type StatsControllerGetMyStatsQueryParams = {
|
|
2246
2310
|
/**
|
|
2247
|
-
* @type string
|
|
2311
|
+
* @type string | undefined
|
|
2248
2312
|
*/
|
|
2249
|
-
workspace_id
|
|
2313
|
+
workspace_id?: string;
|
|
2250
2314
|
};
|
|
2251
2315
|
|
|
2252
2316
|
/**
|
|
@@ -2306,12 +2370,6 @@ declare class JwksFetchError extends JwtVerifyError {
|
|
|
2306
2370
|
}
|
|
2307
2371
|
|
|
2308
2372
|
interface HeimdallConfig extends PCClientConfig {
|
|
2309
|
-
/**
|
|
2310
|
-
* Override the default `audience` claim expected on tokens verified
|
|
2311
|
-
* via `consumer(slug).verifyToken(...)`. Per-call override is also
|
|
2312
|
-
* available on `verifyToken`'s options.
|
|
2313
|
-
*/
|
|
2314
|
-
expectedAudience?: string;
|
|
2315
2373
|
/** Per-app JWKS cache lifetime in ms. Default 10 minutes. */
|
|
2316
2374
|
jwksTtlMs?: number;
|
|
2317
2375
|
}
|
|
@@ -2351,4 +2409,4 @@ declare class Heimdall {
|
|
|
2351
2409
|
};
|
|
2352
2410
|
}
|
|
2353
2411
|
|
|
2354
|
-
export { type AcceptInviteDto, AppScope, type AssignRoleDto, type AuthorizeBatchBody, type AuthorizeBody, type ClientCredentialsDto, type ConsumerLogoutDto, type ConsumerRefreshDto, type ConsumerRequestPasswordResetDto, type ConsumerResetPasswordDto, ConsumerScope, type ConsumerSigninDto, type ConsumerSignupDto, type ConsumerTokenResponseDto, type CreateApiKeyDto, type CreateAppDto, type CreateInviteDto, type CreateM2MClientDto, type CreatePermissionDto, type CreateRoleDto, Heimdall, type HeimdallClaims, type HeimdallConfig, HeimdallHttpError, type IdpNativeSigninDto, type IdpNativeUserHintDto, type IdpTokenResponseDto, JwksCache, JwksFetchError, JwksKeyNotFoundError, JwtAudienceMismatchError, JwtExpiredError, JwtInvalidError, JwtIssuerMismatchError, JwtNotYetValidError, JwtVerifyError, type SetPermissionsDto, type SetScopesDto, type UpdateAppDto, type UpdateAppStatusDto, type UpdateAuthConfigDto, type UpdateEndUserDto, type UpdateEndUserRoleDto, type UpdateEndUserStatusDto, type UpdateM2MClientDto, type UpdateMeDto, type UpdateRoleDto, type VerifyBody, type VerifyOptions, verifyHeimdallToken };
|
|
2412
|
+
export { type AcceptInviteDto, AppScope, type AssignRoleDto, type AuthorizeBatchBody, type AuthorizeBody, type ClientCredentialsDto, type ConsumerLogoutDto, type ConsumerRefreshDto, type ConsumerRequestPasswordResetDto, type ConsumerResetPasswordDto, ConsumerScope, type ConsumerSigninDto, type ConsumerSignupDto, type ConsumerTokenResponseDto, type CreateApiKeyDto, type CreateAppDto, type CreateInviteDto, type CreateM2MClientDto, type CreatePermissionDto, type CreateRoleDto, HEIMDALL_LEGACY_ISSUER, Heimdall, type HeimdallClaims, type HeimdallConfig, HeimdallHttpError, type IdpNativeSigninDto, type IdpNativeUserHintDto, type IdpTokenResponseDto, JwksCache, JwksFetchError, JwksKeyNotFoundError, JwtAudienceMismatchError, JwtExpiredError, JwtInvalidError, JwtIssuerMismatchError, JwtNotYetValidError, JwtVerifyError, type SetPermissionsDto, type SetScopesDto, type UpdateAppDto, type UpdateAppStatusDto, type UpdateAuthConfigDto, type UpdateEndUserDto, type UpdateEndUserRoleDto, type UpdateEndUserStatusDto, type UpdateM2MClientDto, type UpdateMeDto, type UpdateRoleDto, type VerifyBody, type VerifyOptions, verifyHeimdallToken };
|
package/dist/index.js
CHANGED
|
@@ -1414,7 +1414,8 @@ function getConsumerVerifyControllerVerifyUrl({
|
|
|
1414
1414
|
}
|
|
1415
1415
|
async function consumerVerifyControllerVerify({
|
|
1416
1416
|
appSlug,
|
|
1417
|
-
data
|
|
1417
|
+
data,
|
|
1418
|
+
headers
|
|
1418
1419
|
}, config = {}) {
|
|
1419
1420
|
const { client: request = client, ...requestConfig } = config;
|
|
1420
1421
|
const requestData = data;
|
|
@@ -1422,7 +1423,8 @@ async function consumerVerifyControllerVerify({
|
|
|
1422
1423
|
method: "POST",
|
|
1423
1424
|
url: getConsumerVerifyControllerVerifyUrl({ appSlug }).url.toString(),
|
|
1424
1425
|
data: requestData,
|
|
1425
|
-
...requestConfig
|
|
1426
|
+
...requestConfig,
|
|
1427
|
+
headers: { ...headers, ...requestConfig.headers }
|
|
1426
1428
|
});
|
|
1427
1429
|
return res.data;
|
|
1428
1430
|
}
|
|
@@ -1437,7 +1439,8 @@ function getConsumerVerifyControllerAuthorizeUrl({
|
|
|
1437
1439
|
}
|
|
1438
1440
|
async function consumerVerifyControllerAuthorize({
|
|
1439
1441
|
appSlug,
|
|
1440
|
-
data
|
|
1442
|
+
data,
|
|
1443
|
+
headers
|
|
1441
1444
|
}, config = {}) {
|
|
1442
1445
|
const { client: request = client, ...requestConfig } = config;
|
|
1443
1446
|
const requestData = data;
|
|
@@ -1445,7 +1448,8 @@ async function consumerVerifyControllerAuthorize({
|
|
|
1445
1448
|
method: "POST",
|
|
1446
1449
|
url: getConsumerVerifyControllerAuthorizeUrl({ appSlug }).url.toString(),
|
|
1447
1450
|
data: requestData,
|
|
1448
|
-
...requestConfig
|
|
1451
|
+
...requestConfig,
|
|
1452
|
+
headers: { ...headers, ...requestConfig.headers }
|
|
1449
1453
|
});
|
|
1450
1454
|
return res.data;
|
|
1451
1455
|
}
|
|
@@ -1463,7 +1467,8 @@ function getConsumerVerifyControllerAuthorizeBatchUrl({
|
|
|
1463
1467
|
}
|
|
1464
1468
|
async function consumerVerifyControllerAuthorizeBatch({
|
|
1465
1469
|
appSlug,
|
|
1466
|
-
data
|
|
1470
|
+
data,
|
|
1471
|
+
headers
|
|
1467
1472
|
}, config = {}) {
|
|
1468
1473
|
const { client: request = client, ...requestConfig } = config;
|
|
1469
1474
|
const requestData = data;
|
|
@@ -1473,7 +1478,8 @@ async function consumerVerifyControllerAuthorizeBatch({
|
|
|
1473
1478
|
appSlug
|
|
1474
1479
|
}).url.toString(),
|
|
1475
1480
|
data: requestData,
|
|
1476
|
-
...requestConfig
|
|
1481
|
+
...requestConfig,
|
|
1482
|
+
headers: { ...headers, ...requestConfig.headers }
|
|
1477
1483
|
});
|
|
1478
1484
|
return res.data;
|
|
1479
1485
|
}
|
|
@@ -1654,21 +1660,49 @@ function translateJoseError(err) {
|
|
|
1654
1660
|
}
|
|
1655
1661
|
|
|
1656
1662
|
// src/scopes/consumer.ts
|
|
1663
|
+
var HEIMDALL_LEGACY_ISSUER = "heimdall";
|
|
1657
1664
|
var ConsumerScope = class {
|
|
1658
1665
|
/** The appSlug bound to this scope. */
|
|
1659
1666
|
appSlug;
|
|
1660
|
-
/**
|
|
1667
|
+
/**
|
|
1668
|
+
* Issuer the Heimdall Consumer API stamps on every token for this
|
|
1669
|
+
* app — the public Heimdall API base joined with the app slug
|
|
1670
|
+
* (e.g. `https://api.heimdall.productcraft.co/acme`). Pin it in
|
|
1671
|
+
* your local verifier so a token minted for another app on the
|
|
1672
|
+
* platform cannot pass.
|
|
1673
|
+
*
|
|
1674
|
+
* `scope.verifyToken` already enforces this for you. Pass it as a
|
|
1675
|
+
* second-position issuer if you're wiring `jose.jwtVerify`,
|
|
1676
|
+
* `passport-jwt`, or PyJWT yourself.
|
|
1677
|
+
*/
|
|
1661
1678
|
expectedIssuer;
|
|
1662
|
-
/**
|
|
1679
|
+
/**
|
|
1680
|
+
* Audience the Consumer API stamps on every token for this app —
|
|
1681
|
+
* literally the app slug (e.g. `"acme"`). Pin it in your verifier
|
|
1682
|
+
* the same way as `expectedIssuer`. `scope.verifyToken` enforces
|
|
1683
|
+
* it by default.
|
|
1684
|
+
*/
|
|
1663
1685
|
expectedAudience;
|
|
1686
|
+
/**
|
|
1687
|
+
* Both accepted issuer strings (`expectedIssuer` + the legacy
|
|
1688
|
+
* `'heimdall'` literal). `verifyToken` passes this to jose so tokens
|
|
1689
|
+
* minted before the 2026-05-24 per-app-issuer migration keep
|
|
1690
|
+
* verifying alongside fresh ones — useful for the ~1-hour transition
|
|
1691
|
+
* window per access-token TTL, and the longer session TTL on
|
|
1692
|
+
* refresh tokens.
|
|
1693
|
+
*/
|
|
1694
|
+
acceptedIssuers;
|
|
1664
1695
|
/** jose-compatible JWKS resolver. Drop into `jose.jwtVerify`, passport-jwt, etc. */
|
|
1665
1696
|
jwks;
|
|
1666
1697
|
client;
|
|
1667
1698
|
constructor(appSlug, internals, opts = {}) {
|
|
1668
1699
|
this.appSlug = appSlug;
|
|
1669
1700
|
this.client = internals.client;
|
|
1670
|
-
|
|
1671
|
-
|
|
1701
|
+
const apiOrigin = new URL(internals.baseUrl);
|
|
1702
|
+
apiOrigin.pathname = `/${appSlug}`;
|
|
1703
|
+
this.expectedIssuer = apiOrigin.toString().replace(/\/$/, "");
|
|
1704
|
+
this.expectedAudience = appSlug;
|
|
1705
|
+
this.acceptedIssuers = [this.expectedIssuer, HEIMDALL_LEGACY_ISSUER];
|
|
1672
1706
|
this.jwks = new JwksCache({
|
|
1673
1707
|
url: new URL(`/${appSlug}/v1/.well-known/jwks.json`, internals.baseUrl),
|
|
1674
1708
|
ttlMs: opts.jwksTtlMs,
|
|
@@ -1684,10 +1718,20 @@ var ConsumerScope = class {
|
|
|
1684
1718
|
const res = await this.client({ method, url, data: body, params });
|
|
1685
1719
|
return res.data;
|
|
1686
1720
|
}
|
|
1687
|
-
/**
|
|
1721
|
+
/**
|
|
1722
|
+
* Verify a Heimdall-issued JWT against this app's JWKS.
|
|
1723
|
+
*
|
|
1724
|
+
* Checks the signature, expiry, `iss`, and `aud`. Accepts both the
|
|
1725
|
+
* per-app issuer URL (`expectedIssuer`) and the legacy `'heimdall'`
|
|
1726
|
+
* literal during the issuer-migration transition window — callers
|
|
1727
|
+
* who want to refuse legacy tokens can override with
|
|
1728
|
+
* `{ issuer: scope.expectedIssuer }`. Audience defaults to the app
|
|
1729
|
+
* slug (`expectedAudience`); pass `{ audience: false }` (in an
|
|
1730
|
+
* options override) to skip the audience check entirely.
|
|
1731
|
+
*/
|
|
1688
1732
|
verifyToken(token, opts = {}) {
|
|
1689
1733
|
return verifyHeimdallToken(token, this.jwks.getKey, {
|
|
1690
|
-
issuer: this.
|
|
1734
|
+
issuer: this.acceptedIssuers,
|
|
1691
1735
|
audience: this.expectedAudience,
|
|
1692
1736
|
...opts
|
|
1693
1737
|
});
|
|
@@ -1800,16 +1844,23 @@ var ConsumerScope = class {
|
|
|
1800
1844
|
// (typically called by the customer's backend, not the user agent)
|
|
1801
1845
|
// ─────────────────────────────────────────────────────────────
|
|
1802
1846
|
verify = {
|
|
1847
|
+
/**
|
|
1848
|
+
* The kubb-generated client makes `headers.authorization` a required
|
|
1849
|
+
* arg because the server controllers accept the bearer as a fallback
|
|
1850
|
+
* to `body.token`. We stub an empty string here — the HTTP client's
|
|
1851
|
+
* auth middleware overrides whatever's passed with the configured
|
|
1852
|
+
* credential (`PCAuth.apiKey` / `bearer` / `cookie`).
|
|
1853
|
+
*/
|
|
1803
1854
|
verify: (data) => consumerVerifyControllerVerify(
|
|
1804
|
-
{ appSlug: this.appSlug, data },
|
|
1855
|
+
{ appSlug: this.appSlug, data, headers: { authorization: "" } },
|
|
1805
1856
|
{ client: this.client }
|
|
1806
1857
|
),
|
|
1807
1858
|
authorize: (data) => consumerVerifyControllerAuthorize(
|
|
1808
|
-
{ appSlug: this.appSlug, data },
|
|
1859
|
+
{ appSlug: this.appSlug, data, headers: { authorization: "" } },
|
|
1809
1860
|
{ client: this.client }
|
|
1810
1861
|
),
|
|
1811
1862
|
authorizeBatch: (data) => consumerVerifyControllerAuthorizeBatch(
|
|
1812
|
-
{ appSlug: this.appSlug, data },
|
|
1863
|
+
{ appSlug: this.appSlug, data, headers: { authorization: "" } },
|
|
1813
1864
|
{ client: this.client }
|
|
1814
1865
|
)
|
|
1815
1866
|
};
|
|
@@ -1829,7 +1880,7 @@ function getAppControllerListMyAppsUrl() {
|
|
|
1829
1880
|
const res = { method: "GET", url: `/v1/apps` };
|
|
1830
1881
|
return res;
|
|
1831
1882
|
}
|
|
1832
|
-
async function appControllerListMyApps({ params }, config = {}) {
|
|
1883
|
+
async function appControllerListMyApps({ params } = {}, config = {}) {
|
|
1833
1884
|
const { client: request = client, ...requestConfig } = config;
|
|
1834
1885
|
const mappedParams = params ? {
|
|
1835
1886
|
limit: params.limit,
|
|
@@ -1889,7 +1940,7 @@ function getStatsControllerGetMyStatsUrl() {
|
|
|
1889
1940
|
const res = { method: "GET", url: `/v1/stats/me` };
|
|
1890
1941
|
return res;
|
|
1891
1942
|
}
|
|
1892
|
-
async function statsControllerGetMyStats({ params }, config = {}) {
|
|
1943
|
+
async function statsControllerGetMyStats({ params } = {}, config = {}) {
|
|
1893
1944
|
const { client: request = client, ...requestConfig } = config;
|
|
1894
1945
|
const mappedParams = params ? { workspace_id: params.workspaceId } : void 0;
|
|
1895
1946
|
const res = await request({
|
|
@@ -1916,7 +1967,6 @@ var Heimdall = class {
|
|
|
1916
1967
|
fetch: this.fetch
|
|
1917
1968
|
});
|
|
1918
1969
|
this.jwtConfig = {
|
|
1919
|
-
audience: config.expectedAudience,
|
|
1920
1970
|
jwksTtlMs: config.jwksTtlMs
|
|
1921
1971
|
};
|
|
1922
1972
|
}
|
|
@@ -1977,6 +2027,6 @@ var Heimdall = class {
|
|
|
1977
2027
|
};
|
|
1978
2028
|
};
|
|
1979
2029
|
|
|
1980
|
-
export { AppScope, ConsumerScope, Heimdall, HeimdallHttpError, JwksCache, JwksFetchError, JwksKeyNotFoundError, JwtAudienceMismatchError, JwtExpiredError, JwtInvalidError, JwtIssuerMismatchError, JwtNotYetValidError, JwtVerifyError, verifyHeimdallToken };
|
|
2030
|
+
export { AppScope, ConsumerScope, HEIMDALL_LEGACY_ISSUER, Heimdall, HeimdallHttpError, JwksCache, JwksFetchError, JwksKeyNotFoundError, JwtAudienceMismatchError, JwtExpiredError, JwtInvalidError, JwtIssuerMismatchError, JwtNotYetValidError, JwtVerifyError, verifyHeimdallToken };
|
|
1981
2031
|
//# sourceMappingURL=index.js.map
|
|
1982
2032
|
//# sourceMappingURL=index.js.map
|