@thirdweb-dev/service-utils 0.1.1-nightly-4915ac50-20230714041125 → 0.2.0-nightly-5eb6fc1b-20230714082745

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.
Files changed (45) hide show
  1. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.d.ts +2 -0
  2. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.d.ts.map +1 -0
  3. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.dev.js +115 -0
  4. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.js +7 -0
  5. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +115 -0
  6. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +105 -0
  7. package/cf-worker/package.json +4 -0
  8. package/dist/declarations/src/cf-worker/index.d.ts +18 -0
  9. package/dist/declarations/src/cf-worker/index.d.ts.map +1 -0
  10. package/dist/declarations/src/core/api.d.ts +31 -0
  11. package/dist/declarations/src/core/api.d.ts.map +1 -0
  12. package/dist/declarations/src/core/authorize/index.d.ts +18 -0
  13. package/dist/declarations/src/core/authorize/index.d.ts.map +1 -0
  14. package/dist/declarations/src/core/authorize/types.d.ts +11 -0
  15. package/dist/declarations/src/core/authorize/types.d.ts.map +1 -0
  16. package/dist/declarations/src/core/services.d.ts.map +1 -0
  17. package/dist/declarations/src/core/types.d.ts +5 -0
  18. package/dist/declarations/src/core/types.d.ts.map +1 -0
  19. package/dist/declarations/src/index.d.ts +1 -2
  20. package/dist/declarations/src/index.d.ts.map +1 -1
  21. package/dist/declarations/src/node/index.d.ts +16 -0
  22. package/dist/declarations/src/node/index.d.ts.map +1 -0
  23. package/dist/index-294e111f.esm.js +252 -0
  24. package/dist/index-3060948e.cjs.prod.js +254 -0
  25. package/dist/index-fcf69a55.cjs.dev.js +254 -0
  26. package/dist/services-86283509.esm.js +44 -0
  27. package/dist/services-9e185105.cjs.prod.js +49 -0
  28. package/dist/services-a3f36057.cjs.dev.js +49 -0
  29. package/dist/thirdweb-dev-service-utils.cjs.dev.js +5 -284
  30. package/dist/thirdweb-dev-service-utils.cjs.prod.js +5 -284
  31. package/dist/thirdweb-dev-service-utils.esm.js +1 -282
  32. package/node/dist/thirdweb-dev-service-utils-node.cjs.d.ts +2 -0
  33. package/node/dist/thirdweb-dev-service-utils-node.cjs.d.ts.map +1 -0
  34. package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +113 -0
  35. package/node/dist/thirdweb-dev-service-utils-node.cjs.js +7 -0
  36. package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +113 -0
  37. package/node/dist/thirdweb-dev-service-utils-node.esm.js +102 -0
  38. package/node/package.json +4 -0
  39. package/package.json +22 -10
  40. package/dist/declarations/src/auth/index.d.ts +0 -4
  41. package/dist/declarations/src/auth/index.d.ts.map +0 -1
  42. package/dist/declarations/src/auth/types.d.ts +0 -61
  43. package/dist/declarations/src/auth/types.d.ts.map +0 -1
  44. package/dist/declarations/src/services.d.ts.map +0 -1
  45. /package/dist/declarations/src/{services.d.ts → core/services.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/cf-worker/index";
2
+ //# sourceMappingURL=thirdweb-dev-service-utils-cf-worker.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thirdweb-dev-service-utils-cf-worker.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/cf-worker/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var index = require('../../dist/index-fcf69a55.cjs.dev.js');
6
+ var services = require('../../dist/services-a3f36057.cjs.dev.js');
7
+
8
+ const DEFAULT_CACHE_TTL_SECONDS = 60;
9
+ async function authorizeWorker(authInput, serviceConfig) {
10
+ let authData;
11
+ try {
12
+ authData = await extractAuthorizationData(authInput);
13
+ } catch (e) {
14
+ if (e instanceof Error && e.message === "KEY_CONFLICT") {
15
+ return {
16
+ authorized: false,
17
+ status: 400,
18
+ errorMessage: "Please pass either a client id or a secret key.",
19
+ errorCode: "KEY_CONFLICT"
20
+ };
21
+ }
22
+ return {
23
+ authorized: false,
24
+ status: 500,
25
+ errorMessage: "Internal Server Error",
26
+ errorCode: "INTERNAL_SERVER_ERROR"
27
+ };
28
+ }
29
+ return await index.authorize(authData, serviceConfig, {
30
+ get: async clientId => serviceConfig.kvStore.get(clientId),
31
+ put: (clientId, apiKeyMeta) => serviceConfig.ctx.waitUntil(serviceConfig.kvStore.put(clientId, JSON.stringify({
32
+ updatedAt: Date.now(),
33
+ apiKeyMeta
34
+ }), {
35
+ expirationTtl: serviceConfig.cacheTtlSeconds && serviceConfig.cacheTtlSeconds >= DEFAULT_CACHE_TTL_SECONDS ? serviceConfig.cacheTtlSeconds : DEFAULT_CACHE_TTL_SECONDS
36
+ })),
37
+ cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
38
+ });
39
+ }
40
+ async function extractAuthorizationData(authInput) {
41
+ const requestUrl = new URL(authInput.req.url);
42
+ const headers = authInput.req.headers;
43
+ const secretKey = headers.get("x-secret-key");
44
+
45
+ // prefer clientId that is explicitly passed in
46
+ let clientId = authInput.clientId ?? null;
47
+ if (!clientId) {
48
+ // next preference is clientId from header
49
+ clientId = headers.get("x-client-id");
50
+ }
51
+
52
+ // next preference is search param
53
+ if (!clientId) {
54
+ clientId = requestUrl.searchParams.get("clientId");
55
+ }
56
+ // bundle id from header is first preference
57
+ let bundleId = headers.get("x-bundle-id");
58
+
59
+ // next preference is search param
60
+ if (!bundleId) {
61
+ bundleId = requestUrl.searchParams.get("bundleId");
62
+ }
63
+ let origin = headers.get("origin");
64
+ // if origin header is not available we'll fall back to referrer;
65
+ if (!origin) {
66
+ origin = headers.get("referer");
67
+ }
68
+ // if we have an origin at this point, normalize it
69
+ if (origin) {
70
+ try {
71
+ origin = new URL(origin).hostname;
72
+ } catch (e) {
73
+ console.warn("failed to parse origin", origin, e);
74
+ }
75
+ }
76
+
77
+ // handle if we a secret key is passed in the headers
78
+ let secretKeyHash = null;
79
+ if (secretKey) {
80
+ // hash the secret key
81
+ secretKeyHash = await hashSecretKey(secretKey);
82
+ // derive the client id from the secret key hash
83
+ const derivedClientId = deriveClientIdFromSecretKeyHash(secretKeyHash);
84
+ // if we already have a client id passed in we need to make sure they match
85
+ if (clientId && clientId !== derivedClientId) {
86
+ throw new Error("KEY_CONFLICT");
87
+ }
88
+ // otherwise set the client id to the derived client id (client id based off of secret key)
89
+ clientId = derivedClientId;
90
+ }
91
+ return {
92
+ secretKey,
93
+ clientId,
94
+ origin,
95
+ bundleId,
96
+ secretKeyHash
97
+ };
98
+ }
99
+ async function hashSecretKey(secretKey) {
100
+ return bufferToHex(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secretKey)));
101
+ }
102
+ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
103
+ return secretKeyHash.slice(0, 32);
104
+ }
105
+ function bufferToHex(buffer) {
106
+ return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
107
+ }
108
+
109
+ exports.SERVICES = services.SERVICES;
110
+ exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
111
+ exports.SERVICE_NAMES = services.SERVICE_NAMES;
112
+ exports.getServiceByName = services.getServiceByName;
113
+ exports.authorizeWorker = authorizeWorker;
114
+ exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
115
+ exports.hashSecretKey = hashSecretKey;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./thirdweb-dev-service-utils-cf-worker.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./thirdweb-dev-service-utils-cf-worker.cjs.dev.js");
7
+ }
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var index = require('../../dist/index-3060948e.cjs.prod.js');
6
+ var services = require('../../dist/services-9e185105.cjs.prod.js');
7
+
8
+ const DEFAULT_CACHE_TTL_SECONDS = 60;
9
+ async function authorizeWorker(authInput, serviceConfig) {
10
+ let authData;
11
+ try {
12
+ authData = await extractAuthorizationData(authInput);
13
+ } catch (e) {
14
+ if (e instanceof Error && e.message === "KEY_CONFLICT") {
15
+ return {
16
+ authorized: false,
17
+ status: 400,
18
+ errorMessage: "Please pass either a client id or a secret key.",
19
+ errorCode: "KEY_CONFLICT"
20
+ };
21
+ }
22
+ return {
23
+ authorized: false,
24
+ status: 500,
25
+ errorMessage: "Internal Server Error",
26
+ errorCode: "INTERNAL_SERVER_ERROR"
27
+ };
28
+ }
29
+ return await index.authorize(authData, serviceConfig, {
30
+ get: async clientId => serviceConfig.kvStore.get(clientId),
31
+ put: (clientId, apiKeyMeta) => serviceConfig.ctx.waitUntil(serviceConfig.kvStore.put(clientId, JSON.stringify({
32
+ updatedAt: Date.now(),
33
+ apiKeyMeta
34
+ }), {
35
+ expirationTtl: serviceConfig.cacheTtlSeconds && serviceConfig.cacheTtlSeconds >= DEFAULT_CACHE_TTL_SECONDS ? serviceConfig.cacheTtlSeconds : DEFAULT_CACHE_TTL_SECONDS
36
+ })),
37
+ cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
38
+ });
39
+ }
40
+ async function extractAuthorizationData(authInput) {
41
+ const requestUrl = new URL(authInput.req.url);
42
+ const headers = authInput.req.headers;
43
+ const secretKey = headers.get("x-secret-key");
44
+
45
+ // prefer clientId that is explicitly passed in
46
+ let clientId = authInput.clientId ?? null;
47
+ if (!clientId) {
48
+ // next preference is clientId from header
49
+ clientId = headers.get("x-client-id");
50
+ }
51
+
52
+ // next preference is search param
53
+ if (!clientId) {
54
+ clientId = requestUrl.searchParams.get("clientId");
55
+ }
56
+ // bundle id from header is first preference
57
+ let bundleId = headers.get("x-bundle-id");
58
+
59
+ // next preference is search param
60
+ if (!bundleId) {
61
+ bundleId = requestUrl.searchParams.get("bundleId");
62
+ }
63
+ let origin = headers.get("origin");
64
+ // if origin header is not available we'll fall back to referrer;
65
+ if (!origin) {
66
+ origin = headers.get("referer");
67
+ }
68
+ // if we have an origin at this point, normalize it
69
+ if (origin) {
70
+ try {
71
+ origin = new URL(origin).hostname;
72
+ } catch (e) {
73
+ console.warn("failed to parse origin", origin, e);
74
+ }
75
+ }
76
+
77
+ // handle if we a secret key is passed in the headers
78
+ let secretKeyHash = null;
79
+ if (secretKey) {
80
+ // hash the secret key
81
+ secretKeyHash = await hashSecretKey(secretKey);
82
+ // derive the client id from the secret key hash
83
+ const derivedClientId = deriveClientIdFromSecretKeyHash(secretKeyHash);
84
+ // if we already have a client id passed in we need to make sure they match
85
+ if (clientId && clientId !== derivedClientId) {
86
+ throw new Error("KEY_CONFLICT");
87
+ }
88
+ // otherwise set the client id to the derived client id (client id based off of secret key)
89
+ clientId = derivedClientId;
90
+ }
91
+ return {
92
+ secretKey,
93
+ clientId,
94
+ origin,
95
+ bundleId,
96
+ secretKeyHash
97
+ };
98
+ }
99
+ async function hashSecretKey(secretKey) {
100
+ return bufferToHex(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secretKey)));
101
+ }
102
+ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
103
+ return secretKeyHash.slice(0, 32);
104
+ }
105
+ function bufferToHex(buffer) {
106
+ return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
107
+ }
108
+
109
+ exports.SERVICES = services.SERVICES;
110
+ exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
111
+ exports.SERVICE_NAMES = services.SERVICE_NAMES;
112
+ exports.getServiceByName = services.getServiceByName;
113
+ exports.authorizeWorker = authorizeWorker;
114
+ exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
115
+ exports.hashSecretKey = hashSecretKey;
@@ -0,0 +1,105 @@
1
+ import { a as authorize } from '../../dist/index-294e111f.esm.js';
2
+ export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
3
+
4
+ const DEFAULT_CACHE_TTL_SECONDS = 60;
5
+ async function authorizeWorker(authInput, serviceConfig) {
6
+ let authData;
7
+ try {
8
+ authData = await extractAuthorizationData(authInput);
9
+ } catch (e) {
10
+ if (e instanceof Error && e.message === "KEY_CONFLICT") {
11
+ return {
12
+ authorized: false,
13
+ status: 400,
14
+ errorMessage: "Please pass either a client id or a secret key.",
15
+ errorCode: "KEY_CONFLICT"
16
+ };
17
+ }
18
+ return {
19
+ authorized: false,
20
+ status: 500,
21
+ errorMessage: "Internal Server Error",
22
+ errorCode: "INTERNAL_SERVER_ERROR"
23
+ };
24
+ }
25
+ return await authorize(authData, serviceConfig, {
26
+ get: async clientId => serviceConfig.kvStore.get(clientId),
27
+ put: (clientId, apiKeyMeta) => serviceConfig.ctx.waitUntil(serviceConfig.kvStore.put(clientId, JSON.stringify({
28
+ updatedAt: Date.now(),
29
+ apiKeyMeta
30
+ }), {
31
+ expirationTtl: serviceConfig.cacheTtlSeconds && serviceConfig.cacheTtlSeconds >= DEFAULT_CACHE_TTL_SECONDS ? serviceConfig.cacheTtlSeconds : DEFAULT_CACHE_TTL_SECONDS
32
+ })),
33
+ cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
34
+ });
35
+ }
36
+ async function extractAuthorizationData(authInput) {
37
+ const requestUrl = new URL(authInput.req.url);
38
+ const headers = authInput.req.headers;
39
+ const secretKey = headers.get("x-secret-key");
40
+
41
+ // prefer clientId that is explicitly passed in
42
+ let clientId = authInput.clientId ?? null;
43
+ if (!clientId) {
44
+ // next preference is clientId from header
45
+ clientId = headers.get("x-client-id");
46
+ }
47
+
48
+ // next preference is search param
49
+ if (!clientId) {
50
+ clientId = requestUrl.searchParams.get("clientId");
51
+ }
52
+ // bundle id from header is first preference
53
+ let bundleId = headers.get("x-bundle-id");
54
+
55
+ // next preference is search param
56
+ if (!bundleId) {
57
+ bundleId = requestUrl.searchParams.get("bundleId");
58
+ }
59
+ let origin = headers.get("origin");
60
+ // if origin header is not available we'll fall back to referrer;
61
+ if (!origin) {
62
+ origin = headers.get("referer");
63
+ }
64
+ // if we have an origin at this point, normalize it
65
+ if (origin) {
66
+ try {
67
+ origin = new URL(origin).hostname;
68
+ } catch (e) {
69
+ console.warn("failed to parse origin", origin, e);
70
+ }
71
+ }
72
+
73
+ // handle if we a secret key is passed in the headers
74
+ let secretKeyHash = null;
75
+ if (secretKey) {
76
+ // hash the secret key
77
+ secretKeyHash = await hashSecretKey(secretKey);
78
+ // derive the client id from the secret key hash
79
+ const derivedClientId = deriveClientIdFromSecretKeyHash(secretKeyHash);
80
+ // if we already have a client id passed in we need to make sure they match
81
+ if (clientId && clientId !== derivedClientId) {
82
+ throw new Error("KEY_CONFLICT");
83
+ }
84
+ // otherwise set the client id to the derived client id (client id based off of secret key)
85
+ clientId = derivedClientId;
86
+ }
87
+ return {
88
+ secretKey,
89
+ clientId,
90
+ origin,
91
+ bundleId,
92
+ secretKeyHash
93
+ };
94
+ }
95
+ async function hashSecretKey(secretKey) {
96
+ return bufferToHex(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secretKey)));
97
+ }
98
+ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
99
+ return secretKeyHash.slice(0, 32);
100
+ }
101
+ function bufferToHex(buffer) {
102
+ return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
103
+ }
104
+
105
+ export { authorizeWorker, deriveClientIdFromSecretKeyHash, hashSecretKey };
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/thirdweb-dev-service-utils-cf-worker.cjs.js",
3
+ "module": "dist/thirdweb-dev-service-utils-cf-worker.esm.js"
4
+ }
@@ -0,0 +1,18 @@
1
+ import type { ExecutionContext, KVNamespace } from "@cloudflare/workers-types";
2
+ import type { CoreServiceConfig } from "../core/api.js";
3
+ import type { Request } from "@cloudflare/workers-types";
4
+ import type { AuthorizationResult } from "../core/authorize/types.js";
5
+ import type { CoreAuthInput } from "../core/types.js";
6
+ export * from "../core/services.js";
7
+ type WorkerServiceConfig = CoreServiceConfig & {
8
+ kvStore: KVNamespace;
9
+ ctx: ExecutionContext;
10
+ cacheTtlSeconds?: number;
11
+ };
12
+ type AuthInput = CoreAuthInput & {
13
+ req: Request;
14
+ };
15
+ export declare function authorizeWorker(authInput: AuthInput, serviceConfig: WorkerServiceConfig): Promise<AuthorizationResult>;
16
+ export declare function hashSecretKey(secretKey: string): Promise<string>;
17
+ export declare function deriveClientIdFromSecretKeyHash(secretKeyHash: string): string;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,EAAkB,iBAAiB,EAAE,uBAAoB;AAGrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAgC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAsB;AAEnD,oCAAiC;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;AAmED,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,mBAIpD;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
@@ -0,0 +1,31 @@
1
+ import type { ServiceName } from "./services.js";
2
+ export type CoreServiceConfig = {
3
+ apiUrl: string;
4
+ serviceScope: ServiceName;
5
+ serviceApiKey: string;
6
+ serviceAction?: string;
7
+ };
8
+ export type ApiKeyMetadata = {
9
+ id: string;
10
+ key: string;
11
+ creatorWalletAddress: string;
12
+ secretHash: string;
13
+ walletAddresses: string[];
14
+ domains: string[];
15
+ bundleIds: string[];
16
+ services: {
17
+ name: string;
18
+ targetAddresses: string[];
19
+ actions: string[];
20
+ }[];
21
+ };
22
+ export type ApiResponse = {
23
+ data: ApiKeyMetadata | null;
24
+ error: {
25
+ code: string;
26
+ statusCode: number;
27
+ message: string;
28
+ };
29
+ };
30
+ export declare function fetchKeyMetadataFromApi(clientId: string, config: CoreServiceConfig): Promise<ApiResponse>;
31
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"../../../../src/core","sources":["api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAmB;AAE9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,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,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,CAkBtB"}
@@ -0,0 +1,18 @@
1
+ import { ApiKeyMetadata, CoreServiceConfig } from "../api.js";
2
+ import { AuthorizationResult } from "./types.js";
3
+ export type AuthorizationInput = {
4
+ secretKey: string | null;
5
+ clientId: string | null;
6
+ origin: string | null;
7
+ bundleId: string | null;
8
+ secretKeyHash: string | null;
9
+ targetAddress?: string;
10
+ };
11
+ type CacheOptions = {
12
+ get: (clientId: string) => Promise<string | null>;
13
+ put: (clientId: string, data: ApiKeyMetadata) => Promise<void> | void;
14
+ cacheTtlSeconds: number;
15
+ };
16
+ export declare function authorize(authData: AuthorizationInput, serviceConfig: CoreServiceConfig, cacheOptions?: CacheOptions): Promise<AuthorizationResult>;
17
+ export {};
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,iBAAiB,EAElB,kBAAe;AAGhB,OAAO,EAAE,mBAAmB,EAAE,mBAAgB;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,CAAC;CACxB,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,CAoH9B"}
@@ -0,0 +1,11 @@
1
+ import { ApiKeyMetadata } from "../api.js";
2
+ export type AuthorizationResult = {
3
+ authorized: true;
4
+ apiKeyMeta: ApiKeyMetadata;
5
+ } | {
6
+ authorized: false;
7
+ status: number;
8
+ errorMessage: string;
9
+ errorCode: string;
10
+ };
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAe;AAExC,MAAM,MAAM,mBAAmB,GAC3B;IACE,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,cAAc,CAAC;CAC5B,GACD;IACE,UAAU,EAAE,KAAK,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.d.ts","sourceRoot":"../../../../src/core","sources":["services.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCtB,CAAC;AAEX,eAAO,MAAM,aAAa,+CAEe,CAAC;AAE1C,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAqC,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,GACjB,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAEjE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEjD"}
@@ -0,0 +1,5 @@
1
+ export type CoreAuthInput = {
2
+ clientId?: string;
3
+ targetAddress?: string;
4
+ };
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"../../../../src/core","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAE1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC"}
@@ -1,3 +1,2 @@
1
- export * from "./services";
2
- export * from "./auth";
1
+ export * from "./core/services.js";
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,mCAAgC"}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage } from "node:http";
3
+ import type { AuthorizationInput } from "../core/authorize/index.js";
4
+ import type { CoreServiceConfig } from "../core/api.js";
5
+ import type { AuthorizationResult } from "../core/authorize/types.js";
6
+ import type { CoreAuthInput } from "../core/types.js";
7
+ export * from "../core/services.js";
8
+ type NodeServiceConfig = CoreServiceConfig;
9
+ export type AuthInput = CoreAuthInput & {
10
+ req: IncomingMessage;
11
+ };
12
+ export declare function authorizeNode(authInput: AuthInput, serviceConfig: NodeServiceConfig): Promise<AuthorizationResult>;
13
+ export declare function extractAuthorizationData(authInput: AuthInput): AuthorizationInput;
14
+ export declare function hashSecretKey(secretKey: string): string;
15
+ export declare function deriveClientIdFromSecretKeyHash(secretKeyHash: string): string;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,mCAA0B;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAoB;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAgC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAsB;AAEnD,oCAAiC;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,CA+DpB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}