@thirdweb-dev/service-utils 0.0.0-dev-8e57e1d-20230731190300 → 0.0.0-dev-619fe6f-20230731210829
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/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.dev.js +1 -13
- package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +1 -13
- package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +1 -13
- package/dist/declarations/src/cf-worker/index.d.ts +4 -4
- package/dist/declarations/src/cf-worker/index.d.ts.map +1 -1
- package/dist/declarations/src/core/api.d.ts +1 -15
- package/dist/declarations/src/core/api.d.ts.map +1 -1
- package/dist/declarations/src/core/authorize/client.d.ts +9 -0
- package/dist/declarations/src/core/authorize/client.d.ts.map +1 -0
- package/dist/declarations/src/core/authorize/index.d.ts +3 -5
- package/dist/declarations/src/core/authorize/index.d.ts.map +1 -1
- package/dist/declarations/src/core/authorize/service.d.ts +7 -0
- package/dist/declarations/src/core/authorize/service.d.ts.map +1 -0
- package/dist/declarations/src/core/authorize/types.d.ts +1 -2
- package/dist/declarations/src/core/authorize/types.d.ts.map +1 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/declarations/src/node/index.d.ts +5 -5
- package/dist/declarations/src/node/index.d.ts.map +1 -1
- package/dist/{index-794f8b68.cjs.prod.js → index-4496b57e.cjs.dev.js} +9 -144
- package/dist/{index-ca7a4739.cjs.dev.js → index-7c6b47cd.cjs.prod.js} +9 -144
- package/dist/{index-80604116.esm.js → index-d752cff8.esm.js} +9 -144
- package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +1 -12
- package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +1 -12
- package/node/dist/thirdweb-dev-service-utils-node.esm.js +1 -12
- package/package.json +3 -3
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var index = require('../../dist/index-
|
5
|
+
var index = require('../../dist/index-4496b57e.cjs.dev.js');
|
6
6
|
var services = require('../../dist/services-a3f36057.cjs.dev.js');
|
7
7
|
|
8
8
|
const DEFAULT_CACHE_TTL_SECONDS = 60;
|
@@ -88,19 +88,7 @@ async function extractAuthorizationData(authInput) {
|
|
88
88
|
// otherwise set the client id to the derived client id (client id based off of secret key)
|
89
89
|
clientId = derivedClientId;
|
90
90
|
}
|
91
|
-
let jwt = null;
|
92
|
-
if (headers.has("authorization")) {
|
93
|
-
const authHeader = headers.get("authorization");
|
94
|
-
if (authHeader) {
|
95
|
-
const [type, token] = authHeader.split(" ");
|
96
|
-
if (type.toLowerCase() === "bearer") {
|
97
|
-
jwt = token;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
91
|
return {
|
102
|
-
jwt,
|
103
|
-
hashedJWT: jwt ? await hashSecretKey(jwt) : null,
|
104
92
|
secretKey,
|
105
93
|
clientId,
|
106
94
|
origin,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var index = require('../../dist/index-
|
5
|
+
var index = require('../../dist/index-7c6b47cd.cjs.prod.js');
|
6
6
|
var services = require('../../dist/services-9e185105.cjs.prod.js');
|
7
7
|
|
8
8
|
const DEFAULT_CACHE_TTL_SECONDS = 60;
|
@@ -88,19 +88,7 @@ async function extractAuthorizationData(authInput) {
|
|
88
88
|
// otherwise set the client id to the derived client id (client id based off of secret key)
|
89
89
|
clientId = derivedClientId;
|
90
90
|
}
|
91
|
-
let jwt = null;
|
92
|
-
if (headers.has("authorization")) {
|
93
|
-
const authHeader = headers.get("authorization");
|
94
|
-
if (authHeader) {
|
95
|
-
const [type, token] = authHeader.split(" ");
|
96
|
-
if (type.toLowerCase() === "bearer") {
|
97
|
-
jwt = token;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
91
|
return {
|
102
|
-
jwt,
|
103
|
-
hashedJWT: jwt ? await hashSecretKey(jwt) : null,
|
104
92
|
secretKey,
|
105
93
|
clientId,
|
106
94
|
origin,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { a as authorize } from '../../dist/index-
|
1
|
+
import { a as authorize } from '../../dist/index-d752cff8.esm.js';
|
2
2
|
export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
|
3
3
|
|
4
4
|
const DEFAULT_CACHE_TTL_SECONDS = 60;
|
@@ -84,19 +84,7 @@ async function extractAuthorizationData(authInput) {
|
|
84
84
|
// otherwise set the client id to the derived client id (client id based off of secret key)
|
85
85
|
clientId = derivedClientId;
|
86
86
|
}
|
87
|
-
let jwt = null;
|
88
|
-
if (headers.has("authorization")) {
|
89
|
-
const authHeader = headers.get("authorization");
|
90
|
-
if (authHeader) {
|
91
|
-
const [type, token] = authHeader.split(" ");
|
92
|
-
if (type.toLowerCase() === "bearer") {
|
93
|
-
jwt = token;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
87
|
return {
|
98
|
-
jwt,
|
99
|
-
hashedJWT: jwt ? await hashSecretKey(jwt) : null,
|
100
88
|
secretKey,
|
101
89
|
clientId,
|
102
90
|
origin,
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { ExecutionContext, KVNamespace } from "@cloudflare/workers-types";
|
2
|
-
import type { CoreServiceConfig } from "../core/api
|
2
|
+
import type { CoreServiceConfig } from "../core/api";
|
3
3
|
import type { Request } from "@cloudflare/workers-types";
|
4
|
-
import type { AuthorizationResult } from "../core/authorize/types
|
5
|
-
import type { CoreAuthInput } from "../core/types
|
6
|
-
export * from "../core/services
|
4
|
+
import type { AuthorizationResult } from "../core/authorize/types";
|
5
|
+
import type { CoreAuthInput } from "../core/types";
|
6
|
+
export * from "../core/services";
|
7
7
|
type WorkerServiceConfig = CoreServiceConfig & {
|
8
8
|
kvStore: KVNamespace;
|
9
9
|
ctx: ExecutionContext;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAkB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,cAAc,kBAAkB,CAAC;AAEjC,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,OAAO,EAAE,WAAW,CAAC;IACrB,GAAG,EAAE,gBAAgB,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,wBAAsB,eAAe,CACnC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA0C9B;AAoED,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,mBAIpD;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ServiceName } from "./services
|
1
|
+
import type { ServiceName } from "./services";
|
2
2
|
export type CoreServiceConfig = {
|
3
3
|
enforceAuth: boolean;
|
4
4
|
apiUrl: string;
|
@@ -21,11 +21,6 @@ export type ApiKeyMetadata = {
|
|
21
21
|
actions: string[];
|
22
22
|
}[];
|
23
23
|
};
|
24
|
-
export type AccountMetadata = {
|
25
|
-
id: string;
|
26
|
-
name: string;
|
27
|
-
creatorWalletAddress: string;
|
28
|
-
};
|
29
24
|
export type ApiResponse = {
|
30
25
|
data: ApiKeyMetadata | null;
|
31
26
|
error: {
|
@@ -34,14 +29,5 @@ export type ApiResponse = {
|
|
34
29
|
message: string;
|
35
30
|
};
|
36
31
|
};
|
37
|
-
export type ApiAccountResponse = {
|
38
|
-
data: AccountMetadata | null;
|
39
|
-
error: {
|
40
|
-
code: string;
|
41
|
-
statusCode: number;
|
42
|
-
message: string;
|
43
|
-
};
|
44
|
-
};
|
45
32
|
export declare function fetchKeyMetadataFromApi(clientId: string, config: CoreServiceConfig): Promise<ApiResponse>;
|
46
|
-
export declare function fetchAccountFromApi(jwt: string, config: CoreServiceConfig): Promise<ApiAccountResponse>;
|
47
33
|
//# sourceMappingURL=api.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"../../../../src/core","sources":["api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"../../../../src/core","sources":["api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,WAAW,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,EAAE,CAAC;QAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,WAAW,CAAC,CAgBtB"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { ApiKeyMetadata } from "../api";
|
2
|
+
import type { AuthorizationResult } from "./types";
|
3
|
+
export type ClientAuthorizationPayload = {
|
4
|
+
secretKeyHash: string | null;
|
5
|
+
bundleId: string | null;
|
6
|
+
origin: string | null;
|
7
|
+
};
|
8
|
+
export declare function authorizeClient(authOptions: ClientAuthorizationPayload, apiKeyMeta: ApiKeyMetadata): AuthorizationResult;
|
9
|
+
//# sourceMappingURL=client.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,WAAW,EAAE,0BAA0B,EACvC,UAAU,EAAE,cAAc,GACzB,mBAAmB,CAsFrB"}
|
@@ -1,18 +1,16 @@
|
|
1
|
-
import {
|
2
|
-
import { AuthorizationResult } from "./types
|
1
|
+
import { ApiKeyMetadata, CoreServiceConfig } from "../api";
|
2
|
+
import { AuthorizationResult } from "./types";
|
3
3
|
export type AuthorizationInput = {
|
4
4
|
secretKey: string | null;
|
5
5
|
clientId: string | null;
|
6
6
|
origin: string | null;
|
7
7
|
bundleId: string | null;
|
8
8
|
secretKeyHash: string | null;
|
9
|
-
jwt: string | null;
|
10
|
-
hashedJWT: string | null;
|
11
9
|
targetAddress?: string | string[];
|
12
10
|
};
|
13
11
|
type CacheOptions = {
|
14
12
|
get: (clientId: string) => Promise<string | null>;
|
15
|
-
put: (clientId: string, data: ApiKeyMetadata
|
13
|
+
put: (clientId: string, data: ApiKeyMetadata) => Promise<void> | void;
|
16
14
|
cacheTtlSeconds: number;
|
17
15
|
};
|
18
16
|
export declare function authorize(authData: AuthorizationInput, serviceConfig: CoreServiceConfig, cacheOptions?: CacheOptions): Promise<AuthorizationResult>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,iBAAiB,EAElB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClD,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtE,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AASF,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,kBAAkB,EAC5B,aAAa,EAAE,iBAAiB,EAChC,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAiI9B"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ApiKeyMetadata, CoreServiceConfig } from "../api";
|
2
|
+
import { AuthorizationResult } from "./types";
|
3
|
+
export type ServiceAuthorizationPayload = {
|
4
|
+
targetAddress?: string | string[];
|
5
|
+
};
|
6
|
+
export declare function authorizeService(apiKeyMetadata: ApiKeyMetadata, serviceConfig: CoreServiceConfig, authorizationPayload?: ServiceAuthorizationPayload): AuthorizationResult;
|
7
|
+
//# sourceMappingURL=service.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,2BAA2B,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhF,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,iBAAiB,EAChC,oBAAoB,CAAC,EAAE,2BAA2B,GACjD,mBAAmB,CAwDrB"}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { ApiKeyMetadata } from "../api";
|
2
2
|
export type AuthorizationResult = {
|
3
3
|
authorized: true;
|
4
4
|
apiKeyMeta: ApiKeyMetadata | null;
|
5
|
-
accountMeta: AccountMetadata | null;
|
6
5
|
} | {
|
7
6
|
authorized: false;
|
8
7
|
status: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,mBAAmB,GAC3B;IACE,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;CACnC,GACD;IACE,UAAU,EAAE,KAAK,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./core/services
|
1
|
+
export * from "./core/services";
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC"}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import type { IncomingMessage } from "node:http";
|
3
|
-
import type { AuthorizationInput } from "../core/authorize
|
4
|
-
import type { CoreServiceConfig } from "../core/api
|
5
|
-
import type { AuthorizationResult } from "../core/authorize/types
|
6
|
-
import type { CoreAuthInput } from "../core/types
|
7
|
-
export * from "../core/services
|
3
|
+
import type { AuthorizationInput } from "../core/authorize";
|
4
|
+
import type { CoreServiceConfig } from "../core/api";
|
5
|
+
import type { AuthorizationResult } from "../core/authorize/types";
|
6
|
+
import type { CoreAuthInput } from "../core/types";
|
7
|
+
export * from "../core/services";
|
8
8
|
type NodeServiceConfig = CoreServiceConfig;
|
9
9
|
export type AuthInput = CoreAuthInput & {
|
10
10
|
req: IncomingMessage;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,cAAc,kBAAkB,CAAC;AAEjC,KAAK,iBAAiB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IACtC,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,iBAAiB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAsB9B;AAaD,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAwEpB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
|
@@ -19,25 +19,6 @@ async function fetchKeyMetadataFromApi(clientId, config) {
|
|
19
19
|
}
|
20
20
|
return await response.json();
|
21
21
|
}
|
22
|
-
async function fetchAccountFromApi(jwt, config) {
|
23
|
-
const {
|
24
|
-
apiUrl,
|
25
|
-
serviceApiKey
|
26
|
-
} = config;
|
27
|
-
const url = `${apiUrl}/v1/account/me`;
|
28
|
-
const response = await fetch(url, {
|
29
|
-
method: "GET",
|
30
|
-
headers: {
|
31
|
-
"x-service-api-key": serviceApiKey,
|
32
|
-
"content-type": "application/json",
|
33
|
-
authorization: `Bearer ${jwt}`
|
34
|
-
}
|
35
|
-
});
|
36
|
-
if (!response.ok) {
|
37
|
-
throw new Error(`Error fetching account from API: ${response.statusText}`);
|
38
|
-
}
|
39
|
-
return await response.json();
|
40
|
-
}
|
41
22
|
|
42
23
|
function authorizeClient(authOptions, apiKeyMeta) {
|
43
24
|
const {
|
@@ -61,13 +42,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
61
42
|
}
|
62
43
|
return {
|
63
44
|
authorized: true,
|
64
|
-
apiKeyMeta
|
65
|
-
accountMeta: {
|
66
|
-
id: apiKeyMeta.accountId,
|
67
|
-
// TODO update this later
|
68
|
-
name: "",
|
69
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
70
|
-
}
|
45
|
+
apiKeyMeta
|
71
46
|
};
|
72
47
|
}
|
73
48
|
|
@@ -76,22 +51,14 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
76
51
|
if (
|
77
52
|
// find matching domain, or if all domains allowed
|
78
53
|
domains.find(d => {
|
79
|
-
// if any domain is allowed, we'll return true
|
80
54
|
if (d === "*") {
|
81
55
|
return true;
|
82
56
|
}
|
83
57
|
|
84
|
-
// special rule for `localhost`
|
85
|
-
// if the domain is localhost, we'll allow any origin that starts with localhost
|
86
|
-
if (d === "localhost" && origin.startsWith("localhost")) {
|
87
|
-
return true;
|
88
|
-
}
|
89
|
-
|
90
58
|
// If the allowedDomain has a wildcard,
|
91
59
|
// we'll check that the ending of our domain matches the wildcard
|
92
60
|
if (d.startsWith("*.")) {
|
93
|
-
|
94
|
-
const domainRoot = d.slice(1);
|
61
|
+
const domainRoot = d.slice(2);
|
95
62
|
return origin.endsWith(domainRoot);
|
96
63
|
}
|
97
64
|
|
@@ -100,13 +67,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
100
67
|
})) {
|
101
68
|
return {
|
102
69
|
authorized: true,
|
103
|
-
apiKeyMeta
|
104
|
-
accountMeta: {
|
105
|
-
id: apiKeyMeta.accountId,
|
106
|
-
// TODO update this later
|
107
|
-
name: "",
|
108
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
109
|
-
}
|
70
|
+
apiKeyMeta
|
110
71
|
};
|
111
72
|
}
|
112
73
|
return {
|
@@ -129,13 +90,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
129
90
|
})) {
|
130
91
|
return {
|
131
92
|
authorized: true,
|
132
|
-
apiKeyMeta
|
133
|
-
accountMeta: {
|
134
|
-
id: apiKeyMeta.accountId,
|
135
|
-
// TODO update this later
|
136
|
-
name: "",
|
137
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
138
|
-
}
|
93
|
+
apiKeyMeta
|
139
94
|
};
|
140
95
|
}
|
141
96
|
return {
|
@@ -197,11 +152,6 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
|
|
197
152
|
}
|
198
153
|
return {
|
199
154
|
authorized: true,
|
200
|
-
accountMeta: {
|
201
|
-
id: apiKeyMetadata.accountId,
|
202
|
-
name: "",
|
203
|
-
creatorWalletAddress: apiKeyMetadata.creatorWalletAddress
|
204
|
-
},
|
205
155
|
apiKeyMeta: apiKeyMetadata
|
206
156
|
};
|
207
157
|
}
|
@@ -210,97 +160,18 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
210
160
|
const {
|
211
161
|
clientId,
|
212
162
|
targetAddress,
|
213
|
-
secretKeyHash
|
214
|
-
jwt,
|
215
|
-
hashedJWT
|
163
|
+
secretKeyHash
|
216
164
|
} = authData;
|
217
165
|
const {
|
218
166
|
enforceAuth
|
219
167
|
} = serviceConfig;
|
220
168
|
|
221
|
-
// BACKWARDS COMPAT: if auth not enforced and
|
169
|
+
// BACKWARDS COMPAT: if auth not enforced and
|
170
|
+
// we don't have auth credentials bypass
|
222
171
|
if (!enforceAuth && !clientId && !secretKeyHash) {
|
223
172
|
return {
|
224
173
|
authorized: true,
|
225
|
-
apiKeyMeta: null
|
226
|
-
accountMeta: null
|
227
|
-
};
|
228
|
-
}
|
229
|
-
// if we come in with a JWT then we only check the account is valid
|
230
|
-
if (jwt && hashedJWT) {
|
231
|
-
let accountMeta = null;
|
232
|
-
if (cacheOptions) {
|
233
|
-
try {
|
234
|
-
const cachedAccountInfo = await cacheOptions.get(hashedJWT);
|
235
|
-
if (cachedAccountInfo) {
|
236
|
-
const parsed = JSON.parse(cachedAccountInfo);
|
237
|
-
if ("updatedAt" in parsed) {
|
238
|
-
// we want to compare the updatedAt time to the current time
|
239
|
-
// if the difference is greater than the cacheTtl we want to ignore the cached data
|
240
|
-
const now = Date.now();
|
241
|
-
const diff = now - parsed.updatedAt;
|
242
|
-
const cacheTtl = cacheOptions.cacheTtlSeconds * 1000;
|
243
|
-
// only if the diff is less than the cacheTtl do we want to use the cached key
|
244
|
-
if (diff < cacheTtl * 1000) {
|
245
|
-
accountMeta = parsed.apiKeyMeta;
|
246
|
-
}
|
247
|
-
} else {
|
248
|
-
accountMeta = parsed;
|
249
|
-
}
|
250
|
-
}
|
251
|
-
} catch (err) {
|
252
|
-
// ignore errors, proceed as if not in cache
|
253
|
-
}
|
254
|
-
}
|
255
|
-
if (!accountMeta) {
|
256
|
-
try {
|
257
|
-
const {
|
258
|
-
data,
|
259
|
-
error
|
260
|
-
} = await fetchAccountFromApi(jwt, serviceConfig);
|
261
|
-
if (error) {
|
262
|
-
return {
|
263
|
-
authorized: false,
|
264
|
-
errorCode: error.code,
|
265
|
-
errorMessage: error.message,
|
266
|
-
status: error.statusCode
|
267
|
-
};
|
268
|
-
} else if (!data) {
|
269
|
-
return {
|
270
|
-
authorized: false,
|
271
|
-
errorCode: "NO_ACCOUNT",
|
272
|
-
errorMessage: "No error but also no account returned.",
|
273
|
-
status: 500
|
274
|
-
};
|
275
|
-
}
|
276
|
-
accountMeta = data;
|
277
|
-
if (cacheOptions) {
|
278
|
-
await cacheOptions.put(hashedJWT, accountMeta);
|
279
|
-
}
|
280
|
-
} catch (err) {
|
281
|
-
console.warn("failed to fetch account from api", err);
|
282
|
-
return {
|
283
|
-
authorized: false,
|
284
|
-
status: 500,
|
285
|
-
errorMessage: "Failed to account information.",
|
286
|
-
errorCode: "FAILED_TO_ACCOUNT"
|
287
|
-
};
|
288
|
-
}
|
289
|
-
}
|
290
|
-
// if we still don't have an accountMeta at this point we can't authorize
|
291
|
-
if (!accountMeta) {
|
292
|
-
return {
|
293
|
-
authorized: false,
|
294
|
-
status: 401,
|
295
|
-
errorMessage: "Missing account information.",
|
296
|
-
errorCode: "MISSING_ACCOUNT"
|
297
|
-
};
|
298
|
-
}
|
299
|
-
// otherwise we want to return early with the accountMeta
|
300
|
-
return {
|
301
|
-
authorized: true,
|
302
|
-
apiKeyMeta: null,
|
303
|
-
accountMeta
|
174
|
+
apiKeyMeta: null
|
304
175
|
};
|
305
176
|
}
|
306
177
|
|
@@ -414,13 +285,7 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
414
285
|
// if we reach this point we are authorized!
|
415
286
|
return {
|
416
287
|
authorized: true,
|
417
|
-
apiKeyMeta
|
418
|
-
accountMeta: {
|
419
|
-
id: apiKeyMeta.accountId,
|
420
|
-
// TODO update this later
|
421
|
-
name: "",
|
422
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
423
|
-
}
|
288
|
+
apiKeyMeta
|
424
289
|
};
|
425
290
|
}
|
426
291
|
|
@@ -19,25 +19,6 @@ async function fetchKeyMetadataFromApi(clientId, config) {
|
|
19
19
|
}
|
20
20
|
return await response.json();
|
21
21
|
}
|
22
|
-
async function fetchAccountFromApi(jwt, config) {
|
23
|
-
const {
|
24
|
-
apiUrl,
|
25
|
-
serviceApiKey
|
26
|
-
} = config;
|
27
|
-
const url = `${apiUrl}/v1/account/me`;
|
28
|
-
const response = await fetch(url, {
|
29
|
-
method: "GET",
|
30
|
-
headers: {
|
31
|
-
"x-service-api-key": serviceApiKey,
|
32
|
-
"content-type": "application/json",
|
33
|
-
authorization: `Bearer ${jwt}`
|
34
|
-
}
|
35
|
-
});
|
36
|
-
if (!response.ok) {
|
37
|
-
throw new Error(`Error fetching account from API: ${response.statusText}`);
|
38
|
-
}
|
39
|
-
return await response.json();
|
40
|
-
}
|
41
22
|
|
42
23
|
function authorizeClient(authOptions, apiKeyMeta) {
|
43
24
|
const {
|
@@ -61,13 +42,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
61
42
|
}
|
62
43
|
return {
|
63
44
|
authorized: true,
|
64
|
-
apiKeyMeta
|
65
|
-
accountMeta: {
|
66
|
-
id: apiKeyMeta.accountId,
|
67
|
-
// TODO update this later
|
68
|
-
name: "",
|
69
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
70
|
-
}
|
45
|
+
apiKeyMeta
|
71
46
|
};
|
72
47
|
}
|
73
48
|
|
@@ -76,22 +51,14 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
76
51
|
if (
|
77
52
|
// find matching domain, or if all domains allowed
|
78
53
|
domains.find(d => {
|
79
|
-
// if any domain is allowed, we'll return true
|
80
54
|
if (d === "*") {
|
81
55
|
return true;
|
82
56
|
}
|
83
57
|
|
84
|
-
// special rule for `localhost`
|
85
|
-
// if the domain is localhost, we'll allow any origin that starts with localhost
|
86
|
-
if (d === "localhost" && origin.startsWith("localhost")) {
|
87
|
-
return true;
|
88
|
-
}
|
89
|
-
|
90
58
|
// If the allowedDomain has a wildcard,
|
91
59
|
// we'll check that the ending of our domain matches the wildcard
|
92
60
|
if (d.startsWith("*.")) {
|
93
|
-
|
94
|
-
const domainRoot = d.slice(1);
|
61
|
+
const domainRoot = d.slice(2);
|
95
62
|
return origin.endsWith(domainRoot);
|
96
63
|
}
|
97
64
|
|
@@ -100,13 +67,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
100
67
|
})) {
|
101
68
|
return {
|
102
69
|
authorized: true,
|
103
|
-
apiKeyMeta
|
104
|
-
accountMeta: {
|
105
|
-
id: apiKeyMeta.accountId,
|
106
|
-
// TODO update this later
|
107
|
-
name: "",
|
108
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
109
|
-
}
|
70
|
+
apiKeyMeta
|
110
71
|
};
|
111
72
|
}
|
112
73
|
return {
|
@@ -129,13 +90,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
129
90
|
})) {
|
130
91
|
return {
|
131
92
|
authorized: true,
|
132
|
-
apiKeyMeta
|
133
|
-
accountMeta: {
|
134
|
-
id: apiKeyMeta.accountId,
|
135
|
-
// TODO update this later
|
136
|
-
name: "",
|
137
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
138
|
-
}
|
93
|
+
apiKeyMeta
|
139
94
|
};
|
140
95
|
}
|
141
96
|
return {
|
@@ -197,11 +152,6 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
|
|
197
152
|
}
|
198
153
|
return {
|
199
154
|
authorized: true,
|
200
|
-
accountMeta: {
|
201
|
-
id: apiKeyMetadata.accountId,
|
202
|
-
name: "",
|
203
|
-
creatorWalletAddress: apiKeyMetadata.creatorWalletAddress
|
204
|
-
},
|
205
155
|
apiKeyMeta: apiKeyMetadata
|
206
156
|
};
|
207
157
|
}
|
@@ -210,97 +160,18 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
210
160
|
const {
|
211
161
|
clientId,
|
212
162
|
targetAddress,
|
213
|
-
secretKeyHash
|
214
|
-
jwt,
|
215
|
-
hashedJWT
|
163
|
+
secretKeyHash
|
216
164
|
} = authData;
|
217
165
|
const {
|
218
166
|
enforceAuth
|
219
167
|
} = serviceConfig;
|
220
168
|
|
221
|
-
// BACKWARDS COMPAT: if auth not enforced and
|
169
|
+
// BACKWARDS COMPAT: if auth not enforced and
|
170
|
+
// we don't have auth credentials bypass
|
222
171
|
if (!enforceAuth && !clientId && !secretKeyHash) {
|
223
172
|
return {
|
224
173
|
authorized: true,
|
225
|
-
apiKeyMeta: null
|
226
|
-
accountMeta: null
|
227
|
-
};
|
228
|
-
}
|
229
|
-
// if we come in with a JWT then we only check the account is valid
|
230
|
-
if (jwt && hashedJWT) {
|
231
|
-
let accountMeta = null;
|
232
|
-
if (cacheOptions) {
|
233
|
-
try {
|
234
|
-
const cachedAccountInfo = await cacheOptions.get(hashedJWT);
|
235
|
-
if (cachedAccountInfo) {
|
236
|
-
const parsed = JSON.parse(cachedAccountInfo);
|
237
|
-
if ("updatedAt" in parsed) {
|
238
|
-
// we want to compare the updatedAt time to the current time
|
239
|
-
// if the difference is greater than the cacheTtl we want to ignore the cached data
|
240
|
-
const now = Date.now();
|
241
|
-
const diff = now - parsed.updatedAt;
|
242
|
-
const cacheTtl = cacheOptions.cacheTtlSeconds * 1000;
|
243
|
-
// only if the diff is less than the cacheTtl do we want to use the cached key
|
244
|
-
if (diff < cacheTtl * 1000) {
|
245
|
-
accountMeta = parsed.apiKeyMeta;
|
246
|
-
}
|
247
|
-
} else {
|
248
|
-
accountMeta = parsed;
|
249
|
-
}
|
250
|
-
}
|
251
|
-
} catch (err) {
|
252
|
-
// ignore errors, proceed as if not in cache
|
253
|
-
}
|
254
|
-
}
|
255
|
-
if (!accountMeta) {
|
256
|
-
try {
|
257
|
-
const {
|
258
|
-
data,
|
259
|
-
error
|
260
|
-
} = await fetchAccountFromApi(jwt, serviceConfig);
|
261
|
-
if (error) {
|
262
|
-
return {
|
263
|
-
authorized: false,
|
264
|
-
errorCode: error.code,
|
265
|
-
errorMessage: error.message,
|
266
|
-
status: error.statusCode
|
267
|
-
};
|
268
|
-
} else if (!data) {
|
269
|
-
return {
|
270
|
-
authorized: false,
|
271
|
-
errorCode: "NO_ACCOUNT",
|
272
|
-
errorMessage: "No error but also no account returned.",
|
273
|
-
status: 500
|
274
|
-
};
|
275
|
-
}
|
276
|
-
accountMeta = data;
|
277
|
-
if (cacheOptions) {
|
278
|
-
await cacheOptions.put(hashedJWT, accountMeta);
|
279
|
-
}
|
280
|
-
} catch (err) {
|
281
|
-
console.warn("failed to fetch account from api", err);
|
282
|
-
return {
|
283
|
-
authorized: false,
|
284
|
-
status: 500,
|
285
|
-
errorMessage: "Failed to account information.",
|
286
|
-
errorCode: "FAILED_TO_ACCOUNT"
|
287
|
-
};
|
288
|
-
}
|
289
|
-
}
|
290
|
-
// if we still don't have an accountMeta at this point we can't authorize
|
291
|
-
if (!accountMeta) {
|
292
|
-
return {
|
293
|
-
authorized: false,
|
294
|
-
status: 401,
|
295
|
-
errorMessage: "Missing account information.",
|
296
|
-
errorCode: "MISSING_ACCOUNT"
|
297
|
-
};
|
298
|
-
}
|
299
|
-
// otherwise we want to return early with the accountMeta
|
300
|
-
return {
|
301
|
-
authorized: true,
|
302
|
-
apiKeyMeta: null,
|
303
|
-
accountMeta
|
174
|
+
apiKeyMeta: null
|
304
175
|
};
|
305
176
|
}
|
306
177
|
|
@@ -414,13 +285,7 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
414
285
|
// if we reach this point we are authorized!
|
415
286
|
return {
|
416
287
|
authorized: true,
|
417
|
-
apiKeyMeta
|
418
|
-
accountMeta: {
|
419
|
-
id: apiKeyMeta.accountId,
|
420
|
-
// TODO update this later
|
421
|
-
name: "",
|
422
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
423
|
-
}
|
288
|
+
apiKeyMeta
|
424
289
|
};
|
425
290
|
}
|
426
291
|
|
@@ -17,25 +17,6 @@ async function fetchKeyMetadataFromApi(clientId, config) {
|
|
17
17
|
}
|
18
18
|
return await response.json();
|
19
19
|
}
|
20
|
-
async function fetchAccountFromApi(jwt, config) {
|
21
|
-
const {
|
22
|
-
apiUrl,
|
23
|
-
serviceApiKey
|
24
|
-
} = config;
|
25
|
-
const url = `${apiUrl}/v1/account/me`;
|
26
|
-
const response = await fetch(url, {
|
27
|
-
method: "GET",
|
28
|
-
headers: {
|
29
|
-
"x-service-api-key": serviceApiKey,
|
30
|
-
"content-type": "application/json",
|
31
|
-
authorization: `Bearer ${jwt}`
|
32
|
-
}
|
33
|
-
});
|
34
|
-
if (!response.ok) {
|
35
|
-
throw new Error(`Error fetching account from API: ${response.statusText}`);
|
36
|
-
}
|
37
|
-
return await response.json();
|
38
|
-
}
|
39
20
|
|
40
21
|
function authorizeClient(authOptions, apiKeyMeta) {
|
41
22
|
const {
|
@@ -59,13 +40,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
59
40
|
}
|
60
41
|
return {
|
61
42
|
authorized: true,
|
62
|
-
apiKeyMeta
|
63
|
-
accountMeta: {
|
64
|
-
id: apiKeyMeta.accountId,
|
65
|
-
// TODO update this later
|
66
|
-
name: "",
|
67
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
68
|
-
}
|
43
|
+
apiKeyMeta
|
69
44
|
};
|
70
45
|
}
|
71
46
|
|
@@ -74,22 +49,14 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
74
49
|
if (
|
75
50
|
// find matching domain, or if all domains allowed
|
76
51
|
domains.find(d => {
|
77
|
-
// if any domain is allowed, we'll return true
|
78
52
|
if (d === "*") {
|
79
53
|
return true;
|
80
54
|
}
|
81
55
|
|
82
|
-
// special rule for `localhost`
|
83
|
-
// if the domain is localhost, we'll allow any origin that starts with localhost
|
84
|
-
if (d === "localhost" && origin.startsWith("localhost")) {
|
85
|
-
return true;
|
86
|
-
}
|
87
|
-
|
88
56
|
// If the allowedDomain has a wildcard,
|
89
57
|
// we'll check that the ending of our domain matches the wildcard
|
90
58
|
if (d.startsWith("*.")) {
|
91
|
-
|
92
|
-
const domainRoot = d.slice(1);
|
59
|
+
const domainRoot = d.slice(2);
|
93
60
|
return origin.endsWith(domainRoot);
|
94
61
|
}
|
95
62
|
|
@@ -98,13 +65,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
98
65
|
})) {
|
99
66
|
return {
|
100
67
|
authorized: true,
|
101
|
-
apiKeyMeta
|
102
|
-
accountMeta: {
|
103
|
-
id: apiKeyMeta.accountId,
|
104
|
-
// TODO update this later
|
105
|
-
name: "",
|
106
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
107
|
-
}
|
68
|
+
apiKeyMeta
|
108
69
|
};
|
109
70
|
}
|
110
71
|
return {
|
@@ -127,13 +88,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
|
|
127
88
|
})) {
|
128
89
|
return {
|
129
90
|
authorized: true,
|
130
|
-
apiKeyMeta
|
131
|
-
accountMeta: {
|
132
|
-
id: apiKeyMeta.accountId,
|
133
|
-
// TODO update this later
|
134
|
-
name: "",
|
135
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
136
|
-
}
|
91
|
+
apiKeyMeta
|
137
92
|
};
|
138
93
|
}
|
139
94
|
return {
|
@@ -195,11 +150,6 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
|
|
195
150
|
}
|
196
151
|
return {
|
197
152
|
authorized: true,
|
198
|
-
accountMeta: {
|
199
|
-
id: apiKeyMetadata.accountId,
|
200
|
-
name: "",
|
201
|
-
creatorWalletAddress: apiKeyMetadata.creatorWalletAddress
|
202
|
-
},
|
203
153
|
apiKeyMeta: apiKeyMetadata
|
204
154
|
};
|
205
155
|
}
|
@@ -208,97 +158,18 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
208
158
|
const {
|
209
159
|
clientId,
|
210
160
|
targetAddress,
|
211
|
-
secretKeyHash
|
212
|
-
jwt,
|
213
|
-
hashedJWT
|
161
|
+
secretKeyHash
|
214
162
|
} = authData;
|
215
163
|
const {
|
216
164
|
enforceAuth
|
217
165
|
} = serviceConfig;
|
218
166
|
|
219
|
-
// BACKWARDS COMPAT: if auth not enforced and
|
167
|
+
// BACKWARDS COMPAT: if auth not enforced and
|
168
|
+
// we don't have auth credentials bypass
|
220
169
|
if (!enforceAuth && !clientId && !secretKeyHash) {
|
221
170
|
return {
|
222
171
|
authorized: true,
|
223
|
-
apiKeyMeta: null
|
224
|
-
accountMeta: null
|
225
|
-
};
|
226
|
-
}
|
227
|
-
// if we come in with a JWT then we only check the account is valid
|
228
|
-
if (jwt && hashedJWT) {
|
229
|
-
let accountMeta = null;
|
230
|
-
if (cacheOptions) {
|
231
|
-
try {
|
232
|
-
const cachedAccountInfo = await cacheOptions.get(hashedJWT);
|
233
|
-
if (cachedAccountInfo) {
|
234
|
-
const parsed = JSON.parse(cachedAccountInfo);
|
235
|
-
if ("updatedAt" in parsed) {
|
236
|
-
// we want to compare the updatedAt time to the current time
|
237
|
-
// if the difference is greater than the cacheTtl we want to ignore the cached data
|
238
|
-
const now = Date.now();
|
239
|
-
const diff = now - parsed.updatedAt;
|
240
|
-
const cacheTtl = cacheOptions.cacheTtlSeconds * 1000;
|
241
|
-
// only if the diff is less than the cacheTtl do we want to use the cached key
|
242
|
-
if (diff < cacheTtl * 1000) {
|
243
|
-
accountMeta = parsed.apiKeyMeta;
|
244
|
-
}
|
245
|
-
} else {
|
246
|
-
accountMeta = parsed;
|
247
|
-
}
|
248
|
-
}
|
249
|
-
} catch (err) {
|
250
|
-
// ignore errors, proceed as if not in cache
|
251
|
-
}
|
252
|
-
}
|
253
|
-
if (!accountMeta) {
|
254
|
-
try {
|
255
|
-
const {
|
256
|
-
data,
|
257
|
-
error
|
258
|
-
} = await fetchAccountFromApi(jwt, serviceConfig);
|
259
|
-
if (error) {
|
260
|
-
return {
|
261
|
-
authorized: false,
|
262
|
-
errorCode: error.code,
|
263
|
-
errorMessage: error.message,
|
264
|
-
status: error.statusCode
|
265
|
-
};
|
266
|
-
} else if (!data) {
|
267
|
-
return {
|
268
|
-
authorized: false,
|
269
|
-
errorCode: "NO_ACCOUNT",
|
270
|
-
errorMessage: "No error but also no account returned.",
|
271
|
-
status: 500
|
272
|
-
};
|
273
|
-
}
|
274
|
-
accountMeta = data;
|
275
|
-
if (cacheOptions) {
|
276
|
-
await cacheOptions.put(hashedJWT, accountMeta);
|
277
|
-
}
|
278
|
-
} catch (err) {
|
279
|
-
console.warn("failed to fetch account from api", err);
|
280
|
-
return {
|
281
|
-
authorized: false,
|
282
|
-
status: 500,
|
283
|
-
errorMessage: "Failed to account information.",
|
284
|
-
errorCode: "FAILED_TO_ACCOUNT"
|
285
|
-
};
|
286
|
-
}
|
287
|
-
}
|
288
|
-
// if we still don't have an accountMeta at this point we can't authorize
|
289
|
-
if (!accountMeta) {
|
290
|
-
return {
|
291
|
-
authorized: false,
|
292
|
-
status: 401,
|
293
|
-
errorMessage: "Missing account information.",
|
294
|
-
errorCode: "MISSING_ACCOUNT"
|
295
|
-
};
|
296
|
-
}
|
297
|
-
// otherwise we want to return early with the accountMeta
|
298
|
-
return {
|
299
|
-
authorized: true,
|
300
|
-
apiKeyMeta: null,
|
301
|
-
accountMeta
|
172
|
+
apiKeyMeta: null
|
302
173
|
};
|
303
174
|
}
|
304
175
|
|
@@ -412,13 +283,7 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
412
283
|
// if we reach this point we are authorized!
|
413
284
|
return {
|
414
285
|
authorized: true,
|
415
|
-
apiKeyMeta
|
416
|
-
accountMeta: {
|
417
|
-
id: apiKeyMeta.accountId,
|
418
|
-
// TODO update this later
|
419
|
-
name: "",
|
420
|
-
creatorWalletAddress: apiKeyMeta.creatorWalletAddress
|
421
|
-
}
|
286
|
+
apiKeyMeta
|
422
287
|
};
|
423
288
|
}
|
424
289
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var node_crypto = require('node:crypto');
|
6
|
-
var index = require('../../dist/index-
|
6
|
+
var index = require('../../dist/index-4496b57e.cjs.dev.js');
|
7
7
|
var services = require('../../dist/services-a3f36057.cjs.dev.js');
|
8
8
|
|
9
9
|
async function authorizeNode(authInput, serviceConfig) {
|
@@ -91,18 +91,7 @@ function extractAuthorizationData(authInput) {
|
|
91
91
|
// otherwise set the client id to the derived client id (client id based off of secret key)
|
92
92
|
clientId = derivedClientId;
|
93
93
|
}
|
94
|
-
let jwt = null;
|
95
|
-
// check for authorization header on the request
|
96
|
-
const authorizationHeader = getHeader(headers, "authorization");
|
97
|
-
if (authorizationHeader) {
|
98
|
-
const [type, token] = authorizationHeader.split(" ");
|
99
|
-
if (type.toLowerCase() === "bearer") {
|
100
|
-
jwt = token;
|
101
|
-
}
|
102
|
-
}
|
103
94
|
return {
|
104
|
-
jwt,
|
105
|
-
hashedJWT: jwt ? hashSecretKey(jwt) : null,
|
106
95
|
secretKeyHash,
|
107
96
|
secretKey,
|
108
97
|
clientId,
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var node_crypto = require('node:crypto');
|
6
|
-
var index = require('../../dist/index-
|
6
|
+
var index = require('../../dist/index-7c6b47cd.cjs.prod.js');
|
7
7
|
var services = require('../../dist/services-9e185105.cjs.prod.js');
|
8
8
|
|
9
9
|
async function authorizeNode(authInput, serviceConfig) {
|
@@ -91,18 +91,7 @@ function extractAuthorizationData(authInput) {
|
|
91
91
|
// otherwise set the client id to the derived client id (client id based off of secret key)
|
92
92
|
clientId = derivedClientId;
|
93
93
|
}
|
94
|
-
let jwt = null;
|
95
|
-
// check for authorization header on the request
|
96
|
-
const authorizationHeader = getHeader(headers, "authorization");
|
97
|
-
if (authorizationHeader) {
|
98
|
-
const [type, token] = authorizationHeader.split(" ");
|
99
|
-
if (type.toLowerCase() === "bearer") {
|
100
|
-
jwt = token;
|
101
|
-
}
|
102
|
-
}
|
103
94
|
return {
|
104
|
-
jwt,
|
105
|
-
hashedJWT: jwt ? hashSecretKey(jwt) : null,
|
106
95
|
secretKeyHash,
|
107
96
|
secretKey,
|
108
97
|
clientId,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { createHash } from 'node:crypto';
|
2
|
-
import { a as authorize } from '../../dist/index-
|
2
|
+
import { a as authorize } from '../../dist/index-d752cff8.esm.js';
|
3
3
|
export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
|
4
4
|
|
5
5
|
async function authorizeNode(authInput, serviceConfig) {
|
@@ -87,18 +87,7 @@ function extractAuthorizationData(authInput) {
|
|
87
87
|
// otherwise set the client id to the derived client id (client id based off of secret key)
|
88
88
|
clientId = derivedClientId;
|
89
89
|
}
|
90
|
-
let jwt = null;
|
91
|
-
// check for authorization header on the request
|
92
|
-
const authorizationHeader = getHeader(headers, "authorization");
|
93
|
-
if (authorizationHeader) {
|
94
|
-
const [type, token] = authorizationHeader.split(" ");
|
95
|
-
if (type.toLowerCase() === "bearer") {
|
96
|
-
jwt = token;
|
97
|
-
}
|
98
|
-
}
|
99
90
|
return {
|
100
|
-
jwt,
|
101
|
-
hashedJWT: jwt ? hashSecretKey(jwt) : null,
|
102
91
|
secretKeyHash,
|
103
92
|
secretKey,
|
104
93
|
clientId,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thirdweb-dev/service-utils",
|
3
|
-
"version": "0.0.0-dev-
|
3
|
+
"version": "0.0.0-dev-619fe6f-20230731210829",
|
4
4
|
"main": "dist/thirdweb-dev-service-utils.cjs.js",
|
5
5
|
"module": "dist/thirdweb-dev-service-utils.esm.js",
|
6
6
|
"exports": {
|
@@ -40,7 +40,7 @@
|
|
40
40
|
"sideEffects": false,
|
41
41
|
"devDependencies": {
|
42
42
|
"@cloudflare/workers-types": "^4.20230724.0",
|
43
|
-
"@preconstruct/cli": "
|
43
|
+
"@preconstruct/cli": "2.7.0",
|
44
44
|
"@thirdweb-dev/tsconfig": "^0.1.7",
|
45
45
|
"@types/jest": "^29.5.3",
|
46
46
|
"@types/node": "^18.17.1",
|
@@ -48,7 +48,7 @@
|
|
48
48
|
"@typescript-eslint/parser": "^6.2.0",
|
49
49
|
"eslint": "^8.45.0",
|
50
50
|
"eslint-config-prettier": "^8.9.0",
|
51
|
-
"eslint-config-thirdweb": "^0.
|
51
|
+
"eslint-config-thirdweb": "^0.1.6",
|
52
52
|
"jest": "^29.6.2",
|
53
53
|
"prettier": "^3.0.0",
|
54
54
|
"typescript": "^5.1.6"
|