feathers-ucan 0.1.39 → 0.1.41
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/lib/env/version.d.ts +1 -1
- package/lib/index.cjs +35 -25
- package/lib/index.cjs.map +1 -1
- package/lib/index.modern.js +35 -25
- package/lib/index.modern.js.map +1 -1
- package/lib/index.umd.js +35 -25
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
package/lib/env/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.41";
|
package/lib/index.cjs
CHANGED
|
@@ -176,7 +176,18 @@ class UcanStrategy extends authentication.AuthenticationBaseStrategy {
|
|
|
176
176
|
skip_hooks: true,
|
|
177
177
|
admin_pass: true
|
|
178
178
|
}));
|
|
179
|
-
|
|
179
|
+
// Support both paginated and non-paginated service responses
|
|
180
|
+
// - Paginated: { total, limit, skip, data: [...] }
|
|
181
|
+
// - Non-paginated: Array
|
|
182
|
+
let first = undefined;
|
|
183
|
+
if (entities && typeof entities === 'object' && 'data' in entities) {
|
|
184
|
+
var _entities$data;
|
|
185
|
+
first = (_entities$data = entities.data) == null ? void 0 : _entities$data[0];
|
|
186
|
+
} else if (Array.isArray(entities)) {
|
|
187
|
+
first = entities[0];
|
|
188
|
+
}
|
|
189
|
+
if (first && first._id) return first._id;
|
|
190
|
+
throw new NotAuthError$1('Could not find login associated with this ucan');
|
|
180
191
|
}
|
|
181
192
|
}
|
|
182
193
|
async authenticate(authentication, params) {
|
|
@@ -425,7 +436,6 @@ class CoreCall {
|
|
|
425
436
|
return (_this$context$app2 = this.context.app) == null ? void 0 : _this$context$app2.service(this.service).find({
|
|
426
437
|
...params,
|
|
427
438
|
[this.entity]: params[this.entity],
|
|
428
|
-
skip_hooks: true,
|
|
429
439
|
admin_pass: true,
|
|
430
440
|
...{
|
|
431
441
|
[core_path]: this.core
|
|
@@ -492,6 +502,7 @@ class CoreCall {
|
|
|
492
502
|
return (_this$context$app7 = this.context.app) == null ? void 0 : _this$context$app7.service(this.service)._get(id, {
|
|
493
503
|
...params,
|
|
494
504
|
[this.entity]: params[this.entity],
|
|
505
|
+
skip_hooks: true,
|
|
495
506
|
...{
|
|
496
507
|
[core_path]: this.core
|
|
497
508
|
}
|
|
@@ -505,6 +516,7 @@ class CoreCall {
|
|
|
505
516
|
return (_this$context$app8 = this.context.app) == null ? void 0 : _this$context$app8.service(this.service)._find({
|
|
506
517
|
...params,
|
|
507
518
|
[this.entity]: params[this.entity],
|
|
519
|
+
skip_hooks: true,
|
|
508
520
|
...{
|
|
509
521
|
[core_path]: this.core
|
|
510
522
|
}
|
|
@@ -518,6 +530,7 @@ class CoreCall {
|
|
|
518
530
|
return (_this$context$app9 = this.context.app) == null ? void 0 : _this$context$app9.service(this.service)._create(data, {
|
|
519
531
|
...params,
|
|
520
532
|
[this.entity]: params[this.entity],
|
|
533
|
+
skip_hooks: true,
|
|
521
534
|
...{
|
|
522
535
|
[core_path]: this.core
|
|
523
536
|
}
|
|
@@ -531,6 +544,7 @@ class CoreCall {
|
|
|
531
544
|
return (_this$context$app10 = this.context.app) == null ? void 0 : _this$context$app10.service(this.service)._patch(id, data, {
|
|
532
545
|
...params,
|
|
533
546
|
[this.entity]: params[this.entity],
|
|
547
|
+
skip_hooks: true,
|
|
534
548
|
...{
|
|
535
549
|
[core_path]: this.core
|
|
536
550
|
}
|
|
@@ -544,6 +558,7 @@ class CoreCall {
|
|
|
544
558
|
return (_this$context$app11 = this.context.app) == null ? void 0 : _this$context$app11.service(this.service)._update(id, data, {
|
|
545
559
|
...params,
|
|
546
560
|
[this.entity]: params[this.entity],
|
|
561
|
+
skip_hooks: true,
|
|
547
562
|
...{
|
|
548
563
|
[core_path]: this.core
|
|
549
564
|
}
|
|
@@ -557,6 +572,7 @@ class CoreCall {
|
|
|
557
572
|
return (_this$context$app12 = this.context.app) == null ? void 0 : _this$context$app12.service(this.service)._remove(id, {
|
|
558
573
|
...params,
|
|
559
574
|
[this.entity]: params[this.entity],
|
|
575
|
+
skip_hooks: true,
|
|
560
576
|
...{
|
|
561
577
|
[core_path]: this.core
|
|
562
578
|
}
|
|
@@ -660,6 +676,7 @@ const noThrowAuth = async context => {
|
|
|
660
676
|
context = symbolUcan._set(context, [config.core_path, config.entity], entity);
|
|
661
677
|
}
|
|
662
678
|
try {
|
|
679
|
+
// Must pass explicit strategy per app requirements
|
|
663
680
|
context = await authentication.authenticate('jwt')(context).catch(() => {
|
|
664
681
|
return context;
|
|
665
682
|
});
|
|
@@ -672,6 +689,7 @@ const bareAuth = async context => {
|
|
|
672
689
|
const config = context.app.get('authentication');
|
|
673
690
|
const entity = symbolUcan._get(context, ['auth', config.entity]);
|
|
674
691
|
if (entity) context = symbolUcan._set(context, [config.core_path, config.entity], entity);
|
|
692
|
+
// Must pass explicit strategy per app requirements
|
|
675
693
|
return authentication.authenticate('jwt')(context);
|
|
676
694
|
};
|
|
677
695
|
const verifyOne = async (ucan, options, log) => {
|
|
@@ -769,29 +787,21 @@ const verifyAgainstReqs = (reqs, config, options) => {
|
|
|
769
787
|
return async context => {
|
|
770
788
|
var _v3;
|
|
771
789
|
const log = options == null ? void 0 : options.log;
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
logUcanParams('verifyAgainstReqs:start', context);
|
|
778
|
-
} catch {}
|
|
790
|
+
let rawUcan = symbolUcan._get(context.params, config.client_ucan);
|
|
791
|
+
if (!rawUcan) {
|
|
792
|
+
const authCfg = context.app.get('authentication');
|
|
793
|
+
const entityKey = (authCfg == null ? void 0 : authCfg.entity) || 'login';
|
|
794
|
+
rawUcan = symbolUcan._get(context.params, [entityKey, 'ucan']);
|
|
779
795
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
const maybe = symbolUcan.ucanToken(rawUcanFallback);
|
|
790
|
-
if (maybe && typeof maybe === 'string') ucan = maybe;
|
|
791
|
-
if (log && rawUcanFallback !== ucan) console.log('Normalized client UCAN via ucanToken()');
|
|
792
|
-
} catch (e) {
|
|
793
|
-
if (log) console.log('UCAN normalization skipped (ucanToken threw):', e == null ? void 0 : e.message);
|
|
794
|
-
}
|
|
796
|
+
if (log) console.log('get initial ucan', rawUcan);
|
|
797
|
+
let ucan = rawUcan;
|
|
798
|
+
try {
|
|
799
|
+
// ucanToken will stringify a UCAN object or return the compact form for strings
|
|
800
|
+
const maybe = symbolUcan.ucanToken(rawUcan);
|
|
801
|
+
if (maybe && typeof maybe === 'string') ucan = maybe;
|
|
802
|
+
if (log && rawUcan !== ucan) console.log('Normalized client UCAN via ucanToken()');
|
|
803
|
+
} catch (e) {
|
|
804
|
+
if (log) console.log('UCAN normalization skipped (ucanToken threw):', e == null ? void 0 : e.message);
|
|
795
805
|
}
|
|
796
806
|
const audience = (options == null ? void 0 : options.audience) || symbolUcan._get(context.params, config.ucan_aud);
|
|
797
807
|
if (log) console.log('verify against reqs', reqs);
|
|
@@ -1109,7 +1119,7 @@ const ucanAuth = (requiredCapabilities, options) => {
|
|
|
1109
1119
|
const loginId = typeof existingLogin === 'string' ? existingLogin : existingLogin == null ? void 0 : existingLogin._id;
|
|
1110
1120
|
const hasLogin = !!(existingLogin && (typeof existingLogin === 'string' || !!loginId));
|
|
1111
1121
|
// Per requirement: UCAN is always at context.params[entity].ucan
|
|
1112
|
-
const existingUcan = symbolUcan._get(context.params, [entity, 'ucan']);
|
|
1122
|
+
const existingUcan = symbolUcan._get(context.params, configuration.client_ucan || 'client_ucan') || symbolUcan._get(context.params, [entity, 'ucan']);
|
|
1113
1123
|
if (options != null && options.log) console.log('ucan auth', 'hasLogin', hasLogin, 'loginId', loginId, 'existingUcan', !!existingUcan, 'core_path', core_path, 'entity', entity, 'core', context.params[core_path], 'params login', context.params.login, 'required capabilities', requiredCapabilities);
|
|
1114
1124
|
if (options != null && options.log && !hasLogin) {
|
|
1115
1125
|
try {
|