@frogbotai/plugin-api-keys 0.29.0 → 0.31.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.
- package/dist/client/ApiKeysManager.d.ts.map +1 -1
- package/dist/client/ApiKeysManager.js +184 -21
- package/dist/client/ApiKeysManager.js.map +1 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/collection.d.ts +1 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +214 -110
- package/dist/collection.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -39
- package/dist/index.js.map +1 -1
- package/dist/server/services.d.ts.map +1 -1
- package/dist/server/services.js +63 -28
- package/dist/server/services.js.map +1 -1
- package/dist/server/token.js +11 -3
- package/dist/server/token.js.map +1 -1
- package/dist/strategy.d.ts.map +1 -1
- package/dist/strategy.js +51 -29
- package/dist/strategy.js.map +1 -1
- package/package.json +7 -7
- package/dist/client/CostUSD.d.ts +0 -11
- package/dist/client/CostUSD.d.ts.map +0 -1
- package/dist/client/CostUSD.js +0 -19
- package/dist/client/CostUSD.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { createApiKeysCollection } from './collection.js';
|
|
2
2
|
import { apiKeyMeHook, apiKeyStrategyName, createApiKeyStrategy } from './strategy.js';
|
|
3
3
|
export { ApiKeyServiceError, mintApiKey, revokeApiKey, rotateApiKey } from './server/services.js';
|
|
4
|
-
export { createApiKeyToken, extractApiKeyToken, getApiKeyPrefix, hashApiKeyToken
|
|
4
|
+
export { createApiKeyToken, extractApiKeyToken, getApiKeyPrefix, hashApiKeyToken } from './server/token.js';
|
|
5
5
|
export { isApiKeyStrategy } from './strategy.js';
|
|
6
6
|
export function apiKeysPlugin(options = {}) {
|
|
7
|
-
return (config)
|
|
7
|
+
return (config)=>{
|
|
8
8
|
const authCollection = options.authCollection ?? 'users';
|
|
9
9
|
const collectionSlug = options.collectionSlug ?? 'api-keys';
|
|
10
|
-
const auth = config.collections.find((collection)
|
|
10
|
+
const auth = config.collections.find((collection)=>collection.slug === authCollection);
|
|
11
11
|
if (!auth || auth.auth === undefined || auth.auth === false) {
|
|
12
12
|
throw new Error(`[plugin-api-keys] Auth collection '${authCollection}' must exist and have auth enabled.`);
|
|
13
13
|
}
|
|
14
|
-
const existing = config.collections.find((collection)
|
|
15
|
-
const usageLog = config.ai
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
: undefined;
|
|
14
|
+
const existing = config.collections.find((collection)=>collection.slug === collectionSlug);
|
|
15
|
+
const usageLog = config.ai ? config.collections.find((item)=>item.usageLog === true) ?? {
|
|
16
|
+
slug: 'usage-logs',
|
|
17
|
+
usageLog: true,
|
|
18
|
+
fields: []
|
|
19
|
+
} : undefined;
|
|
22
20
|
const collection = createApiKeysCollection({
|
|
23
21
|
authCollection,
|
|
24
22
|
collectionSlug,
|
|
@@ -26,66 +24,88 @@ export function apiKeysPlugin(options = {}) {
|
|
|
26
24
|
usageCollection: usageLog?.slug,
|
|
27
25
|
canRevokeAnyKey: options.canRevokeAnyKey,
|
|
28
26
|
collection: options.collection,
|
|
29
|
-
existing
|
|
27
|
+
existing
|
|
30
28
|
});
|
|
31
29
|
const strategy = createApiKeyStrategy({
|
|
32
30
|
authCollection,
|
|
33
31
|
collectionSlug,
|
|
34
32
|
headerNames: options.headerNames,
|
|
35
|
-
tokenPrefix: options.tokenPrefix ?? 'fb'
|
|
33
|
+
tokenPrefix: options.tokenPrefix ?? 'fb'
|
|
36
34
|
});
|
|
37
35
|
const usageField = {
|
|
38
36
|
name: 'apiKey',
|
|
39
37
|
type: 'relationship',
|
|
40
38
|
relationTo: collectionSlug,
|
|
41
|
-
index: true
|
|
39
|
+
index: true
|
|
42
40
|
};
|
|
43
|
-
const collections = config.collections.map((item)
|
|
41
|
+
const collections = config.collections.map((item)=>{
|
|
44
42
|
let next = item;
|
|
45
|
-
if (item.slug === collectionSlug)
|
|
46
|
-
next = collection;
|
|
43
|
+
if (item.slug === collectionSlug) next = collection;
|
|
47
44
|
if (item.slug === authCollection) {
|
|
48
45
|
const authConfig = typeof next.auth === 'object' ? next.auth : {};
|
|
49
46
|
next = {
|
|
50
47
|
...next,
|
|
51
|
-
auth: {
|
|
52
|
-
|
|
48
|
+
auth: {
|
|
49
|
+
...authConfig,
|
|
50
|
+
strategies: [
|
|
51
|
+
...authConfig.strategies ?? [],
|
|
52
|
+
strategy
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
hooks: {
|
|
56
|
+
...next.hooks,
|
|
57
|
+
me: [
|
|
58
|
+
...next.hooks?.me ?? [],
|
|
59
|
+
apiKeyMeHook
|
|
60
|
+
]
|
|
61
|
+
}
|
|
53
62
|
};
|
|
54
63
|
}
|
|
55
|
-
if (item === usageLog)
|
|
56
|
-
|
|
64
|
+
if (item === usageLog) next = {
|
|
65
|
+
...next,
|
|
66
|
+
fields: [
|
|
67
|
+
...next.fields,
|
|
68
|
+
usageField
|
|
69
|
+
]
|
|
70
|
+
};
|
|
57
71
|
return next;
|
|
58
72
|
});
|
|
59
73
|
return {
|
|
60
74
|
...config,
|
|
61
75
|
collections: [
|
|
62
76
|
...collections,
|
|
63
|
-
...
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
...existing ? [] : [
|
|
78
|
+
collection
|
|
79
|
+
],
|
|
80
|
+
...usageLog && !config.collections.includes(usageLog) ? [
|
|
81
|
+
{
|
|
82
|
+
...usageLog,
|
|
83
|
+
fields: [
|
|
84
|
+
usageField
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
] : []
|
|
67
88
|
],
|
|
68
|
-
...
|
|
89
|
+
...config.ai && {
|
|
69
90
|
ai: {
|
|
70
91
|
...config.ai,
|
|
71
92
|
hooks: {
|
|
72
93
|
...config.ai.hooks,
|
|
73
94
|
beforeOperation: [
|
|
74
|
-
...
|
|
75
|
-
({ req, context })
|
|
95
|
+
...config.ai.hooks?.beforeOperation ?? [],
|
|
96
|
+
({ req, context })=>{
|
|
76
97
|
const user = req?.user;
|
|
77
|
-
const apiKeyId = user?._strategy === apiKeyStrategyName &&
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
98
|
+
const apiKeyId = user?._strategy === apiKeyStrategyName && (typeof user.apiKeyId === 'string' || typeof user.apiKeyId === 'number') ? user.apiKeyId : undefined;
|
|
99
|
+
if (apiKeyId !== undefined) context.usageFields = {
|
|
100
|
+
apiKey: apiKeyId
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
88
107
|
};
|
|
89
108
|
};
|
|
90
109
|
}
|
|
110
|
+
|
|
91
111
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["createApiKeysCollection","apiKeyMeHook","apiKeyStrategyName","createApiKeyStrategy","ApiKeyServiceError","mintApiKey","revokeApiKey","rotateApiKey","createApiKeyToken","extractApiKeyToken","getApiKeyPrefix","hashApiKeyToken","isApiKeyStrategy","apiKeysPlugin","options","config","authCollection","collectionSlug","auth","collections","find","collection","slug","undefined","Error","existing","usageLog","ai","item","fields","tokenPrefix","usageCollection","canRevokeAnyKey","strategy","headerNames","usageField","name","type","relationTo","index","map","next","authConfig","strategies","hooks","me","includes","beforeOperation","req","context","user","apiKeyId","_strategy","usageFields","apiKey"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,kBAAkB;AAC1D,SAASC,YAAY,EAAEC,kBAAkB,EAAEC,oBAAoB,QAAQ,gBAA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KC,QAAQ,KAAK,YAAY,OAAOD,KAAKC,QAAQ,KAAK,QAAO,IAClED,KAAKC,QAAQ,GACb5B;gCAEN,IAAI4B,aAAa5B,WAAW0B,QAAQI,WAAW,GAAG;oCAAEC,QAAQH;gCAAS;4BACvE;yBACD;oBACH;gBACF;YACF,CAAC;QACH;IACF;AACF","file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/server/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,cAAc,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,cAAc,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;aACf,IAAI,EAAE,yBAAyB,GAAG,WAAW;gBAA7C,IAAI,EAAE,yBAAyB,GAAG,WAAW;CAG1E;
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/server/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,cAAc,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,cAAc,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;aACf,IAAI,EAAE,yBAAyB,GAAG,WAAW;gBAA7C,IAAI,EAAE,yBAAyB,GAAG,WAAW;CAG1E;AAuBD,wBAAsB,UAAU,CAAC,OAAO,EAAE,iBAAiB;;;;;;GAW1D;AAED,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,cAAc,EACd,EAAE,EACF,WAAW,EACX,QAAQ,GACT,EAAE,mBAAmB;;;;;;GAUrB;AAED,wBAAsB,YAAY,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,mBAAmB;;;;;GAmC5F"}
|
package/dist/server/services.js
CHANGED
|
@@ -1,73 +1,108 @@
|
|
|
1
1
|
import { createApiKeyToken, getApiKeyPrefix, hashApiKeyToken } from './token.js';
|
|
2
2
|
export class ApiKeyServiceError extends Error {
|
|
3
3
|
code;
|
|
4
|
-
constructor(code)
|
|
5
|
-
super(code);
|
|
6
|
-
this.code = code;
|
|
4
|
+
constructor(code){
|
|
5
|
+
super(code), this.code = code;
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
|
-
async function mintForOwner({ req, collectionSlug, tokenPrefix, name, owner
|
|
10
|
-
const token = createApiKeyToken({
|
|
8
|
+
async function mintForOwner({ req, collectionSlug, tokenPrefix, name, owner }) {
|
|
9
|
+
const token = createApiKeyToken({
|
|
10
|
+
tokenPrefix
|
|
11
|
+
});
|
|
11
12
|
const prefix = getApiKeyPrefix(token);
|
|
12
|
-
const doc =
|
|
13
|
+
const doc = await req.frogbot.create({
|
|
13
14
|
collection: collectionSlug,
|
|
14
|
-
data: {
|
|
15
|
+
data: {
|
|
16
|
+
name,
|
|
17
|
+
owner,
|
|
18
|
+
prefix,
|
|
19
|
+
tokenHash: hashApiKeyToken(token)
|
|
20
|
+
},
|
|
15
21
|
overrideAccess: true,
|
|
16
|
-
req
|
|
17
|
-
})
|
|
18
|
-
return {
|
|
22
|
+
req
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
id: doc.id,
|
|
26
|
+
name,
|
|
27
|
+
prefix,
|
|
28
|
+
token,
|
|
29
|
+
createdAt: doc.createdAt
|
|
30
|
+
};
|
|
19
31
|
}
|
|
20
32
|
export async function mintApiKey(options) {
|
|
21
33
|
const owner = options.req.user?.id;
|
|
22
|
-
if (owner === undefined)
|
|
23
|
-
throw new ApiKeyServiceError('authentication_required');
|
|
34
|
+
if (owner === undefined) throw new ApiKeyServiceError('authentication_required');
|
|
24
35
|
return mintForOwner({
|
|
25
36
|
req: options.req,
|
|
26
37
|
collectionSlug: options.collectionSlug,
|
|
27
38
|
tokenPrefix: options.tokenPrefix,
|
|
28
39
|
name: options.name,
|
|
29
|
-
owner
|
|
40
|
+
owner
|
|
30
41
|
});
|
|
31
42
|
}
|
|
32
|
-
export async function rotateApiKey({ req, collectionSlug, id, tokenPrefix, anyOwner
|
|
33
|
-
const revoked = await revokeApiKey({
|
|
43
|
+
export async function rotateApiKey({ req, collectionSlug, id, tokenPrefix, anyOwner }) {
|
|
44
|
+
const revoked = await revokeApiKey({
|
|
45
|
+
req,
|
|
46
|
+
collectionSlug,
|
|
47
|
+
id,
|
|
48
|
+
anyOwner
|
|
49
|
+
});
|
|
34
50
|
return mintForOwner({
|
|
35
51
|
req,
|
|
36
52
|
collectionSlug,
|
|
37
53
|
tokenPrefix,
|
|
38
54
|
name: revoked.name,
|
|
39
|
-
owner: revoked.owner
|
|
55
|
+
owner: revoked.owner
|
|
40
56
|
});
|
|
41
57
|
}
|
|
42
58
|
export async function revokeApiKey({ req, collectionSlug, id, anyOwner }) {
|
|
43
59
|
const owner = req.user?.id;
|
|
44
|
-
if (owner === undefined)
|
|
45
|
-
throw new ApiKeyServiceError('authentication_required');
|
|
60
|
+
if (owner === undefined) throw new ApiKeyServiceError('authentication_required');
|
|
46
61
|
const result = await req.frogbot.find({
|
|
47
62
|
collection: collectionSlug,
|
|
48
63
|
depth: 0,
|
|
49
64
|
limit: 1,
|
|
50
65
|
overrideAccess: true,
|
|
51
66
|
req,
|
|
52
|
-
where: anyOwner
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
where: anyOwner ? {
|
|
68
|
+
id: {
|
|
69
|
+
equals: id
|
|
70
|
+
}
|
|
71
|
+
} : {
|
|
72
|
+
and: [
|
|
73
|
+
{
|
|
74
|
+
id: {
|
|
75
|
+
equals: id
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
owner: {
|
|
80
|
+
equals: owner
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
55
85
|
});
|
|
56
86
|
const key = result.docs[0];
|
|
57
|
-
if (!key ||
|
|
58
|
-
(typeof key.id !== 'string' && typeof key.id !== 'number') ||
|
|
59
|
-
typeof key.name !== 'string' ||
|
|
60
|
-
(typeof key.owner !== 'string' && typeof key.owner !== 'number')) {
|
|
87
|
+
if (!key || typeof key.id !== 'string' && typeof key.id !== 'number' || typeof key.name !== 'string' || typeof key.owner !== 'string' && typeof key.owner !== 'number') {
|
|
61
88
|
throw new ApiKeyServiceError('not_found');
|
|
62
89
|
}
|
|
63
90
|
const revokedAt = typeof key.revokedAt === 'string' ? key.revokedAt : new Date().toISOString();
|
|
64
91
|
await req.frogbot.update({
|
|
65
92
|
collection: collectionSlug,
|
|
66
93
|
id: key.id,
|
|
67
|
-
data: {
|
|
94
|
+
data: {
|
|
95
|
+
revokedAt
|
|
96
|
+
},
|
|
68
97
|
overrideAccess: true,
|
|
69
|
-
req
|
|
98
|
+
req
|
|
70
99
|
});
|
|
71
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
id: key.id,
|
|
102
|
+
name: key.name,
|
|
103
|
+
owner: key.owner,
|
|
104
|
+
revokedAt
|
|
105
|
+
};
|
|
72
106
|
}
|
|
107
|
+
|
|
73
108
|
//# sourceMappingURL=services.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/server/services.ts"],"names":["createApiKeyToken","getApiKeyPrefix","hashApiKeyToken","ApiKeyServiceError","Error","code","mintForOwner","req","collectionSlug","tokenPrefix","name","owner","token","prefix","doc","frogbot","create","collection","data","tokenHash","overrideAccess","id","createdAt","mintApiKey","options","user","undefined","rotateApiKey","anyOwner","revoked","revokeApiKey","result","find","depth","limit","where","equals","and","key","docs","revokedAt","Date","toISOString","update"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,QAAQ,aAAa;AAgBjF,OAAO,MAAMC,2BAA2BC;;IACtC,YAAY,AAAgBC,IAA6C,CAAE;QACzE,KAAK,CAACA,YADoBA,OAAAA;IAE5B;AACF;AAIA,eAAeC,aAAa,EAC1BC,GAAG,EACHC,cAAc,EACdC,WAAW,EACXC,IAAI,EACJC,KAAK,EACe;IACpB,MAAMC,QAAQZ,kBAAkB;QAAES;IAAY;IAC9C,MAAMI,SAASZ,gBAAgBW;IAC/B,MAAME,MAAO,MAAMP,IAAIQ,OAAO,CAACC,MAAM,CAAC;QACpCC,YAAYT;QACZU,MAAM;YAAER;YAAMC;YAAOE;YAAQM,WAAWjB,gBAAgBU;QAAO;QAC/DQ,gBAAgB;QAChBb;IACF;IAEA,OAAO;QAAEc,IAAIP,IAAIO,EAAE;QAAEX;QAAMG;QAAQD;QAAOU,WAAWR,IAAIQ,SAAS;IAAC;AACrE;AAEA,OAAO,eAAeC,WAAWC,OAA0B;IACzD,MAAMb,QAAQa,QAAQjB,GAAG,CAACkB,IAAI,EAAEJ;IAChC,IAAIV,UAAUe,WAAW,MAAM,IAAIvB,mBAAmB;IAEtD,OAAOG,aAAa;QAClBC,KAAKiB,QAAQjB,GAAG;QAChBC,gBAAgBgB,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,OAAOC,WAAW;IAE5F,MAAMnC,IAAIQ,OAAO,CAAC4B,MAAM,CAAC;QACvB1B,YAAYT;QACZa,IAAIiB,IAAIjB,EAAE;QACVH,MAAM;YAAEsB;QAAU;QAClBpB,gBAAgB;QAChBb;IACF;IAEA,OAAO;QAAEc,IAAIiB,IAAIjB,EAAE;QAAEX,MAAM4B,IAAI5B,IAAI;QAAEC,OAAO2B,IAAI3B,KAAK;QAAE6B;IAAU;AACnE","file":"services.js"}
|
package/dist/server/token.js
CHANGED
|
@@ -12,9 +12,17 @@ function isApiKeyToken(value, { tokenPrefix = 'fb' } = {}) {
|
|
|
12
12
|
const prefix = tokenPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
13
13
|
return new RegExp(`^${prefix}_[A-Za-z0-9_-]{43}$`).test(value);
|
|
14
14
|
}
|
|
15
|
-
export function extractApiKeyToken(headers, { headerNames = [
|
|
15
|
+
export function extractApiKeyToken(headers, { headerNames = [
|
|
16
|
+
'x-api-key'
|
|
17
|
+
], tokenPrefix } = {}) {
|
|
16
18
|
const bearer = headers.get('authorization')?.match(/^Bearer ([^\s]+)$/i)?.[1];
|
|
17
|
-
const candidates = [
|
|
18
|
-
|
|
19
|
+
const candidates = [
|
|
20
|
+
bearer,
|
|
21
|
+
...headerNames.map((headerName)=>headers.get(headerName)?.trim())
|
|
22
|
+
];
|
|
23
|
+
return candidates.find((value)=>value && isApiKeyToken(value, {
|
|
24
|
+
tokenPrefix
|
|
25
|
+
})) ?? null;
|
|
19
26
|
}
|
|
27
|
+
|
|
20
28
|
//# sourceMappingURL=token.js.map
|
package/dist/server/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/server/token.ts"],"names":["createHash","randomBytes","createApiKeyToken","tokenPrefix","toString","hashApiKeyToken","token","update","digest","getApiKeyPrefix","slice","isApiKeyToken","value","prefix","replace","RegExp","test","extractApiKeyToken","headers","headerNames","bearer","get","match","candidates","map","headerName","trim","find"],"mappings":"AAAA,SAASA,UAAU,EAAEC,WAAW,QAAQ,cAAc;AAUtD,OAAO,SAASC,kBAAkB,EAAEC,cAAc,IAAI,EAAsB,GAAG,CAAC,CAAC;IAC/E,OAAO,GAAGA,YAAY,CAAC,EAAEF,YAAY,IAAIG,QAAQ,CAAC,cAAc;AAClE;AAEA,OAAO,SAASC,gBAAgBC,KAAa;IAC3C,OAAON,WAAW,UAAUO,MAAM,CAACD,OAAOE,MAAM,CAAC;AACnD;AAEA,OAAO,SAASC,gBAAgBH,KAAa;IAC3C,OAAOA,MAAMI,KAAK,CAAC,GAAG;AACxB;AAEA,SAASC,cAAcC,KAAa,EAAE,EAAET,cAAc,IAAI,EAAsB,GAAG,CAAC,CAAC;IACnF,MAAMU,SAASV,YAAYW,OAAO,CAAC,uBAAuB;IAE1D,OAAO,IAAIC,OAAO,CAAC,CAAC,EAAEF,OAAO,mBAAmB,CAAC,EAAEG,IAAI,CAACJ;AAC1D;AAEA,OAAO,SAASK,mBACdC,OAAgB,EAChB,EAAEC,cAAc;IAAC;CAAY,EAAEhB,WAAW,EAA4C,GAAG,CAAC,CAAC;IAE3F,MAAMiB,SAASF,QAAQG,GAAG,CAAC,kBAAkBC,MAAM,uBAAuB,CAAC,EAAE;IAC7E,MAAMC,aAAa;QAACH;WAAWD,YAAYK,GAAG,CAAC,CAACC,aAAeP,QAAQG,GAAG,CAACI,aAAaC;KAAQ;IAEhG,OAAOH,WAAWI,IAAI,CAAC,CAACf,QAAUA,SAASD,cAAcC,OAAO;YAAET;QAAY,OAAO;AACvF","file":"token.js"}
|
package/dist/strategy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAI9D,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAI5C,KAAK,eAAe,GAAG;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,eAAe,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAI9D,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAI5C,KAAK,eAAe,GAAG;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,eAAe,GAAG,YAAY,CA+D3E;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAEhE;AAED,eAAO,MAAM,YAAY,EAAE,gBAI1B,CAAC"}
|
package/dist/strategy.js
CHANGED
|
@@ -5,10 +5,14 @@ export function createApiKeyStrategy(options) {
|
|
|
5
5
|
const { authCollection, collectionSlug, headerNames, tokenPrefix } = options;
|
|
6
6
|
const strategy = {
|
|
7
7
|
name: apiKeyStrategyName,
|
|
8
|
-
authenticate: async ({ frogbot, headers })
|
|
9
|
-
const token = extractApiKeyToken(headers, {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
authenticate: async ({ frogbot, headers })=>{
|
|
9
|
+
const token = extractApiKeyToken(headers, {
|
|
10
|
+
headerNames,
|
|
11
|
+
tokenPrefix
|
|
12
|
+
});
|
|
13
|
+
if (!token) return {
|
|
14
|
+
user: null
|
|
15
|
+
};
|
|
12
16
|
const keys = await frogbot.find({
|
|
13
17
|
collection: collectionSlug,
|
|
14
18
|
depth: 0,
|
|
@@ -16,27 +20,41 @@ export function createApiKeyStrategy(options) {
|
|
|
16
20
|
overrideAccess: true,
|
|
17
21
|
where: {
|
|
18
22
|
and: [
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
{
|
|
24
|
+
tokenHash: {
|
|
25
|
+
equals: hashApiKeyToken(token)
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
revokedAt: {
|
|
30
|
+
exists: false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
23
35
|
});
|
|
24
36
|
const key = keys.docs[0];
|
|
25
|
-
if (!key ||
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
if (!key || typeof key.id !== 'string' && typeof key.id !== 'number' || typeof key.owner !== 'string' && typeof key.owner !== 'number') {
|
|
38
|
+
return {
|
|
39
|
+
user: null
|
|
40
|
+
};
|
|
29
41
|
}
|
|
30
|
-
const user = await frogbot
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const user = await frogbot.findByID({
|
|
43
|
+
collection: authCollection,
|
|
44
|
+
id: key.owner,
|
|
45
|
+
depth: 0,
|
|
46
|
+
overrideAccess: true
|
|
47
|
+
}).catch(()=>null);
|
|
48
|
+
if (!user) return {
|
|
49
|
+
user: null
|
|
50
|
+
};
|
|
35
51
|
await frogbot.update({
|
|
36
52
|
collection: collectionSlug,
|
|
37
53
|
id: key.id,
|
|
38
|
-
data: {
|
|
39
|
-
|
|
54
|
+
data: {
|
|
55
|
+
lastUsedAt: new Date().toISOString()
|
|
56
|
+
},
|
|
57
|
+
overrideAccess: true
|
|
40
58
|
});
|
|
41
59
|
return {
|
|
42
60
|
user: {
|
|
@@ -44,13 +62,15 @@ export function createApiKeyStrategy(options) {
|
|
|
44
62
|
collection: authCollection,
|
|
45
63
|
_strategy: apiKeyStrategyName,
|
|
46
64
|
apiKeyId: key.id,
|
|
47
|
-
...
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
65
|
+
...key.capture !== undefined ? {
|
|
66
|
+
capture: key.capture
|
|
67
|
+
} : {},
|
|
68
|
+
...typeof key.captureSampleRate === 'number' ? {
|
|
69
|
+
captureSampleRate: key.captureSampleRate
|
|
70
|
+
} : {}
|
|
71
|
+
}
|
|
52
72
|
};
|
|
53
|
-
}
|
|
73
|
+
}
|
|
54
74
|
};
|
|
55
75
|
apiKeyStrategies.add(strategy);
|
|
56
76
|
return strategy;
|
|
@@ -58,9 +78,11 @@ export function createApiKeyStrategy(options) {
|
|
|
58
78
|
export function isApiKeyStrategy(strategy) {
|
|
59
79
|
return apiKeyStrategies.has(strategy);
|
|
60
80
|
}
|
|
61
|
-
export const apiKeyMeHook = ({ user })
|
|
62
|
-
if (user?._strategy !== apiKeyStrategyName)
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
export const apiKeyMeHook = ({ user })=>{
|
|
82
|
+
if (user?._strategy !== apiKeyStrategyName) return;
|
|
83
|
+
return {
|
|
84
|
+
user
|
|
85
|
+
};
|
|
65
86
|
};
|
|
87
|
+
|
|
66
88
|
//# sourceMappingURL=strategy.js.map
|
package/dist/strategy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/strategy.ts"],"names":["extractApiKeyToken","hashApiKeyToken","apiKeyStrategyName","apiKeyStrategies","WeakSet","createApiKeyStrategy","options","authCollection","collectionSlug","headerNames","tokenPrefix","strategy","name","authenticate","frogbot","headers","token","user","keys","find","collection","depth","limit","overrideAccess","where","and","tokenHash","equals","revokedAt","exists","key","docs","id","owner","findByID","catch","update","data","lastUsedAt","Date","toISOString","_strategy","apiKeyId","capture","undefined","captureSampleRate","add","isApiKeyStrategy","has","apiKeyMeHook"],"mappings":"AAEA,SAASA,kBAAkB,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,IAAIC,OAAOC,WAAW;gBAAG;gBAC7CjB,gBAAgB;YAClB;YAEA,OAAO;gBACLN,MAAM;oBACJ,GAAGA,IAAI;oBACPG,YAAYb;oBACZkC,WAAWvC;oBACXwC,UAAUZ,IAAIE,EAAE;oBAChB,GAAIF,IAAIa,OAAO,KAAKC,YAAY;wBAAED,SAASb,IAAIa,OAAO;oBAAC,IAAI,CAAC,CAAC;oBAC7D,GAAI,OAAOb,IAAIe,iBAAiB,KAAK,WACjC;wBAAEA,mBAAmBf,IAAIe,iBAAiB;oBAAC,IAC3C,CAAC,CAAC;gBACR;YACF;QACF;IACF;IAEA1C,iBAAiB2C,GAAG,CAACnC;IAErB,OAAOA;AACT;AAEA,OAAO,SAASoC,iBAAiBpC,QAAsB;IACrD,OAAOR,iBAAiB6C,GAAG,CAACrC;AAC9B;AAEA,OAAO,MAAMsC,eAAiC,CAAC,EAAEhC,IAAI,EAAE;IACrD,IAAIA,MAAMwB,cAAcvC,oBAAoB;IAE5C,OAAO;QAAEe;IAAK;AAChB,EAAE","file":"strategy.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frogbotai/plugin-api-keys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Multiple named API keys for FrogBot.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Colby Gilbert",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@payloadcms/ui": "3.90.1",
|
|
39
39
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
40
40
|
"react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
41
|
-
"@frogbotai/gateway": "0.
|
|
42
|
-
"frogbot": "0.
|
|
41
|
+
"@frogbotai/gateway": "0.31.0",
|
|
42
|
+
"frogbot": "0.31.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@payloadcms/ui": "3.90.1",
|
|
@@ -48,15 +48,15 @@
|
|
|
48
48
|
"react": "19.2.6",
|
|
49
49
|
"react-dom": "19.2.6",
|
|
50
50
|
"typescript": "5.6.2",
|
|
51
|
-
"@frogbotai/gateway": "0.
|
|
52
|
-
"
|
|
53
|
-
"
|
|
51
|
+
"@frogbotai/gateway": "0.31.0",
|
|
52
|
+
"frogbot": "0.31.0",
|
|
53
|
+
"@frogbotai/plugin-roles": "0.31.0"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
|
-
"build": "
|
|
59
|
+
"build": "node ../../../scripts/build-package.mjs --assets css",
|
|
60
60
|
"clean": "rm -rf dist",
|
|
61
61
|
"typecheck": "tsc --noEmit"
|
|
62
62
|
}
|
package/dist/client/CostUSD.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare function formatCostUSD(value: unknown): string;
|
|
2
|
-
export declare function CostUSDCell({ cellData }: {
|
|
3
|
-
cellData?: unknown;
|
|
4
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
export declare function CostUSDField({ field, path }: {
|
|
6
|
-
field: {
|
|
7
|
-
label?: string;
|
|
8
|
-
};
|
|
9
|
-
path: string;
|
|
10
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
//# sourceMappingURL=CostUSD.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CostUSD.d.ts","sourceRoot":"","sources":["../../src/client/CostUSD.tsx"],"names":[],"mappings":"AAIA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOpD;AAED,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,2CAE/D;AAED,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IAAE,KAAK,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,2CASxF"}
|
package/dist/client/CostUSD.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { FieldLabel, useField } from '@payloadcms/ui';
|
|
4
|
-
export function formatCostUSD(value) {
|
|
5
|
-
return new Intl.NumberFormat('en-US', {
|
|
6
|
-
style: 'currency',
|
|
7
|
-
currency: 'USD',
|
|
8
|
-
minimumFractionDigits: 2,
|
|
9
|
-
maximumFractionDigits: 6,
|
|
10
|
-
}).format(typeof value === 'number' ? value : 0);
|
|
11
|
-
}
|
|
12
|
-
export function CostUSDCell({ cellData }) {
|
|
13
|
-
return _jsx("span", { children: formatCostUSD(cellData) });
|
|
14
|
-
}
|
|
15
|
-
export function CostUSDField({ field, path }) {
|
|
16
|
-
const { value } = useField({ path });
|
|
17
|
-
return (_jsxs("div", { className: "field-type number", children: [_jsx(FieldLabel, { label: field.label, path: path }), _jsx("div", { children: formatCostUSD(value) })] }));
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=CostUSD.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CostUSD.js","sourceRoot":"","sources":["../../src/client/CostUSD.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QACpC,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,KAAK;QACf,qBAAqB,EAAE,CAAC;QACxB,qBAAqB,EAAE,CAAC;KACzB,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAA0B;IAC9D,OAAO,yBAAO,aAAa,CAAC,QAAQ,CAAC,GAAQ,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAA+C;IACvF,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,OAAO,CACL,eAAK,SAAS,EAAC,mBAAmB,aAChC,KAAC,UAAU,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,GAAI,EAC9C,wBAAM,aAAa,CAAC,KAAK,CAAC,GAAO,IAC7B,CACP,CAAC;AACJ,CAAC"}
|