@dynamic-labs-sdk/client 0.17.3 → 0.17.4
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/{InvalidParamError-C8bqZx25.esm.js → InvalidParamError-BgvcmQ36.esm.js} +3 -3
- package/dist/{InvalidParamError-C8bqZx25.esm.js.map → InvalidParamError-BgvcmQ36.esm.js.map} +1 -1
- package/dist/{InvalidParamError-DvFYOkxL.cjs.js → InvalidParamError-CApg0dxd.cjs.js} +4 -4
- package/dist/{InvalidParamError-DvFYOkxL.cjs.js.map → InvalidParamError-CApg0dxd.cjs.js.map} +1 -1
- package/dist/{NotWaasWalletAccountError-CHSFUjd9.cjs.js → NotWaasWalletAccountError-C8iogcNm.cjs.js} +3 -3
- package/dist/{NotWaasWalletAccountError-CHSFUjd9.cjs.js.map → NotWaasWalletAccountError-C8iogcNm.cjs.js.map} +1 -1
- package/dist/{NotWaasWalletAccountError-C-_6uyUM.esm.js → NotWaasWalletAccountError-CfH6ZpRB.esm.js} +3 -3
- package/dist/{NotWaasWalletAccountError-C-_6uyUM.esm.js.map → NotWaasWalletAccountError-CfH6ZpRB.esm.js.map} +1 -1
- package/dist/core.cjs.js +5 -5
- package/dist/core.esm.js +5 -5
- package/dist/{getNetworkProviderFromNetworkId-DK9fnM_Y.cjs.js → getNetworkProviderFromNetworkId-BP2AzuLE.cjs.js} +3 -3
- package/dist/{getNetworkProviderFromNetworkId-DK9fnM_Y.cjs.js.map → getNetworkProviderFromNetworkId-BP2AzuLE.cjs.js.map} +1 -1
- package/dist/{getNetworkProviderFromNetworkId-n7VUDpn0.esm.js → getNetworkProviderFromNetworkId-DoLT1yjR.esm.js} +3 -3
- package/dist/{getNetworkProviderFromNetworkId-n7VUDpn0.esm.js.map → getNetworkProviderFromNetworkId-DoLT1yjR.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-B2-EYPik.cjs.js → getSignedSessionId-CbNoTJxx.cjs.js} +3 -3
- package/dist/{getSignedSessionId-B2-EYPik.cjs.js.map → getSignedSessionId-CbNoTJxx.cjs.js.map} +1 -1
- package/dist/{getSignedSessionId-CM3X3R5t.esm.js → getSignedSessionId-np5XdQ1A.esm.js} +3 -3
- package/dist/{getSignedSessionId-CM3X3R5t.esm.js.map → getSignedSessionId-np5XdQ1A.esm.js.map} +1 -1
- package/dist/{getVerifiedCredentialForWalletAccount-CyLnpS2G.cjs.js → getVerifiedCredentialForWalletAccount-BDXePo9t.cjs.js} +3 -3
- package/dist/{getVerifiedCredentialForWalletAccount-CyLnpS2G.cjs.js.map → getVerifiedCredentialForWalletAccount-BDXePo9t.cjs.js.map} +1 -1
- package/dist/{getVerifiedCredentialForWalletAccount-Cs7AcMKQ.esm.js → getVerifiedCredentialForWalletAccount-CyyHc2ec.esm.js} +2 -2
- package/dist/{getVerifiedCredentialForWalletAccount-Cs7AcMKQ.esm.js.map → getVerifiedCredentialForWalletAccount-CyyHc2ec.esm.js.map} +1 -1
- package/dist/index.cjs.js +10 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +10 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/{isMfaRequiredForAction-CM26tbT2.esm.js → isMfaRequiredForAction-BtO6Xkeu.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-CM26tbT2.esm.js.map → isMfaRequiredForAction-BtO6Xkeu.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-BrRKwK_i.cjs.js → isMfaRequiredForAction-C84laGI8.cjs.js} +2 -2
- package/dist/{isMfaRequiredForAction-BrRKwK_i.cjs.js.map → isMfaRequiredForAction-C84laGI8.cjs.js.map} +1 -1
- package/dist/services/instrumentation/createInstrumentation/createInstrumentation.d.ts.map +1 -1
- package/dist/services/instrumentation/extractSessionId/extractSessionId.d.ts +12 -0
- package/dist/services/instrumentation/extractSessionId/extractSessionId.d.ts.map +1 -0
- package/dist/services/instrumentation/instrumentFunction/extractParams/extractParams.d.ts +27 -0
- package/dist/services/instrumentation/instrumentFunction/extractParams/extractParams.d.ts.map +1 -0
- package/dist/services/instrumentation/instrumentFunction/index.d.ts +2 -0
- package/dist/services/instrumentation/instrumentFunction/index.d.ts.map +1 -0
- package/dist/services/instrumentation/instrumentFunction/instrumentFunction.d.ts +73 -0
- package/dist/services/instrumentation/instrumentFunction/instrumentFunction.d.ts.map +1 -0
- package/dist/services/instrumentation/instrumentFunction/scrubResolvedValue/scrubResolvedValue.d.ts +14 -0
- package/dist/services/instrumentation/instrumentFunction/scrubResolvedValue/scrubResolvedValue.d.ts.map +1 -0
- package/dist/services/instrumentation/instrumentation.types.d.ts +13 -8
- package/dist/services/instrumentation/instrumentation.types.d.ts.map +1 -1
- package/dist/services/instrumentation/transports/createDynamicTransport/createDynamicTransport.d.ts +24 -0
- package/dist/services/instrumentation/transports/createDynamicTransport/createDynamicTransport.d.ts.map +1 -0
- package/dist/services/instrumentation/transports/createDynamicTransport/index.d.ts +2 -0
- package/dist/services/instrumentation/transports/createDynamicTransport/index.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/getUserAgent/getUserAgent.d.ts +10 -0
- package/dist/utils/getUserAgent/getUserAgent.d.ts.map +1 -0
- package/dist/waas.cjs.js +4 -4
- package/dist/waas.esm.js +3 -3
- package/dist/waasCore.cjs.js +4 -4
- package/dist/waasCore.esm.js +3 -3
- package/package.json +3 -3
package/dist/{isMfaRequiredForAction-CM26tbT2.esm.js → isMfaRequiredForAction-BtO6Xkeu.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as getCore, T as assertDefined, j as getDefaultClient, u as createApiClient } from "./InvalidParamError-
|
|
1
|
+
import { F as getCore, T as assertDefined, j as getDefaultClient, u as createApiClient } from "./InvalidParamError-BgvcmQ36.esm.js";
|
|
2
2
|
|
|
3
3
|
//#region src/modules/mfa/consumeMfaToken/consumeMfaToken.ts
|
|
4
4
|
/**
|
|
@@ -59,4 +59,4 @@ const isMfaRequiredForAction = async ({ mfaAction }, client = getDefaultClient()
|
|
|
59
59
|
|
|
60
60
|
//#endregion
|
|
61
61
|
export { getMfaMethods as n, consumeMfaToken as r, isMfaRequiredForAction as t };
|
|
62
|
-
//# sourceMappingURL=isMfaRequiredForAction-
|
|
62
|
+
//# sourceMappingURL=isMfaRequiredForAction-BtO6Xkeu.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isMfaRequiredForAction-
|
|
1
|
+
{"version":3,"file":"isMfaRequiredForAction-BtO6Xkeu.esm.js","names":[],"sources":["../src/modules/mfa/consumeMfaToken/consumeMfaToken.ts","../src/modules/mfa/getMfaMethods/getMfaMethods.ts","../src/modules/mfa/isMfaRequiredForAction/isMfaRequiredForAction.ts"],"sourcesContent":["import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Consumes and clears the current MFA token from the client state.\n *\n * This function retrieves the MFA token obtained from a successful MFA authentication,\n * and removes it from the client, to prevent it from being used again.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The MFA token that was consumed.\n * @throws Error if no MFA token is found.\n */\nexport const consumeMfaToken = (client = getDefaultClient()) => {\n const core = getCore(client);\n\n const mfaToken = core.state.get().mfaToken;\n\n assertDefined(mfaToken, 'No MFA token found');\n\n core.state.set({\n mfaToken: null,\n });\n\n return mfaToken;\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { createApiClient } from '../../apiClient';\n\n/**\n * Retrieves the available MFA methods for the current user.\n *\n * This function fetches information about which multi-factor authentication\n * methods are available and configured for the user's account.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the user's MFA methods configuration.\n */\nexport const getMfaMethods = async (client = getDefaultClient()) => {\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const userMfaMethods = await apiClient.getUserMfaMethods({\n environmentId: core.environmentId,\n verifiedOnly: true,\n });\n\n return userMfaMethods;\n};\n","import type { MFAAction } from '@dynamic-labs/sdk-api-core';\n\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { getMfaMethods } from '../getMfaMethods';\n\ntype IsMfaRequiredForActionParams = {\n mfaAction: MFAAction;\n};\n\n/**\n * Checks if MFA is required for a specific action.\n *\n * This function determines whether multi-factor authentication is required\n * for the specified action based on project settings and user configuration.\n *\n * @param params.mfaAction - The action to check MFA requirements for.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to true if MFA is required for the action, false otherwise.\n */\nexport const isMfaRequiredForAction = async (\n { mfaAction }: IsMfaRequiredForActionParams,\n client = getDefaultClient()\n) => {\n const projectSettings = client.projectSettings;\n\n const isRequiredForAction = projectSettings?.security?.mfa?.actions?.some(\n (action) => action.action === mfaAction && action.required\n );\n\n // if mfa is not required for the action, return false\n // no matter if general mfa is set to required or not\n if (!isRequiredForAction) {\n return false;\n }\n\n const isMfaMethodRequired = projectSettings?.security?.mfa?.required;\n\n // if mfa is required for the action and also set as required in general, return true\n if (isMfaMethodRequired) {\n return true;\n }\n\n const mfaMethods = await getMfaMethods(client);\n // if general mfa is optional, but user has registered methods,\n // then it should be required for the action\n return mfaMethods.userHasVerifiedMfaMethods;\n};\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,mBAAmB,SAAS,kBAAkB,KAAK;CAC9D,MAAM,OAAO,QAAQ,OAAO;CAE5B,MAAM,WAAW,KAAK,MAAM,KAAK,CAAC;AAElC,eAAc,UAAU,qBAAqB;AAE7C,MAAK,MAAM,IAAI,EACb,UAAU,MACX,CAAC;AAEF,QAAO;;;;;;;;;;;;;;ACZT,MAAa,gBAAgB,OAAO,SAAS,kBAAkB,KAAK;CAClE,MAAM,OAAO,QAAQ,OAAO;AAQ5B,QALuB,MAFL,gBAAgB,EAAE,EAAE,OAAO,CAEN,kBAAkB;EACvD,eAAe,KAAK;EACpB,cAAc;EACf,CAAC;;;;;;;;;;;;;;;ACDJ,MAAa,yBAAyB,OACpC,EAAE,aACF,SAAS,kBAAkB,KACxB;CACH,MAAM,kBAAkB,OAAO;AAQ/B,KAAI,CANwB,iBAAiB,UAAU,KAAK,SAAS,MAClE,WAAW,OAAO,WAAW,aAAa,OAAO,SACnD,CAKC,QAAO;AAMT,KAH4B,iBAAiB,UAAU,KAAK,SAI1D,QAAO;AAMT,SAHmB,MAAM,cAAc,OAAO,EAG5B"}
|
package/dist/{isMfaRequiredForAction-BrRKwK_i.cjs.js → isMfaRequiredForAction-C84laGI8.cjs.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_InvalidParamError = require('./InvalidParamError-
|
|
1
|
+
const require_InvalidParamError = require('./InvalidParamError-CApg0dxd.cjs.js');
|
|
2
2
|
|
|
3
3
|
//#region src/modules/mfa/consumeMfaToken/consumeMfaToken.ts
|
|
4
4
|
/**
|
|
@@ -76,4 +76,4 @@ Object.defineProperty(exports, 'isMfaRequiredForAction', {
|
|
|
76
76
|
return isMfaRequiredForAction;
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
-
//# sourceMappingURL=isMfaRequiredForAction-
|
|
79
|
+
//# sourceMappingURL=isMfaRequiredForAction-C84laGI8.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isMfaRequiredForAction-
|
|
1
|
+
{"version":3,"file":"isMfaRequiredForAction-C84laGI8.cjs.js","names":["getDefaultClient","getCore","getDefaultClient","getCore","createApiClient","getDefaultClient"],"sources":["../src/modules/mfa/consumeMfaToken/consumeMfaToken.ts","../src/modules/mfa/getMfaMethods/getMfaMethods.ts","../src/modules/mfa/isMfaRequiredForAction/isMfaRequiredForAction.ts"],"sourcesContent":["import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Consumes and clears the current MFA token from the client state.\n *\n * This function retrieves the MFA token obtained from a successful MFA authentication,\n * and removes it from the client, to prevent it from being used again.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The MFA token that was consumed.\n * @throws Error if no MFA token is found.\n */\nexport const consumeMfaToken = (client = getDefaultClient()) => {\n const core = getCore(client);\n\n const mfaToken = core.state.get().mfaToken;\n\n assertDefined(mfaToken, 'No MFA token found');\n\n core.state.set({\n mfaToken: null,\n });\n\n return mfaToken;\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { createApiClient } from '../../apiClient';\n\n/**\n * Retrieves the available MFA methods for the current user.\n *\n * This function fetches information about which multi-factor authentication\n * methods are available and configured for the user's account.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the user's MFA methods configuration.\n */\nexport const getMfaMethods = async (client = getDefaultClient()) => {\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const userMfaMethods = await apiClient.getUserMfaMethods({\n environmentId: core.environmentId,\n verifiedOnly: true,\n });\n\n return userMfaMethods;\n};\n","import type { MFAAction } from '@dynamic-labs/sdk-api-core';\n\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { getMfaMethods } from '../getMfaMethods';\n\ntype IsMfaRequiredForActionParams = {\n mfaAction: MFAAction;\n};\n\n/**\n * Checks if MFA is required for a specific action.\n *\n * This function determines whether multi-factor authentication is required\n * for the specified action based on project settings and user configuration.\n *\n * @param params.mfaAction - The action to check MFA requirements for.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to true if MFA is required for the action, false otherwise.\n */\nexport const isMfaRequiredForAction = async (\n { mfaAction }: IsMfaRequiredForActionParams,\n client = getDefaultClient()\n) => {\n const projectSettings = client.projectSettings;\n\n const isRequiredForAction = projectSettings?.security?.mfa?.actions?.some(\n (action) => action.action === mfaAction && action.required\n );\n\n // if mfa is not required for the action, return false\n // no matter if general mfa is set to required or not\n if (!isRequiredForAction) {\n return false;\n }\n\n const isMfaMethodRequired = projectSettings?.security?.mfa?.required;\n\n // if mfa is required for the action and also set as required in general, return true\n if (isMfaMethodRequired) {\n return true;\n }\n\n const mfaMethods = await getMfaMethods(client);\n // if general mfa is optional, but user has registered methods,\n // then it should be required for the action\n return mfaMethods.userHasVerifiedMfaMethods;\n};\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,mBAAmB,SAASA,4CAAkB,KAAK;CAC9D,MAAM,OAAOC,kCAAQ,OAAO;CAE5B,MAAM,WAAW,KAAK,MAAM,KAAK,CAAC;AAElC,yCAAc,UAAU,qBAAqB;AAE7C,MAAK,MAAM,IAAI,EACb,UAAU,MACX,CAAC;AAEF,QAAO;;;;;;;;;;;;;;ACZT,MAAa,gBAAgB,OAAO,SAASC,4CAAkB,KAAK;CAClE,MAAM,OAAOC,kCAAQ,OAAO;AAQ5B,QALuB,MAFLC,0CAAgB,EAAE,EAAE,OAAO,CAEN,kBAAkB;EACvD,eAAe,KAAK;EACpB,cAAc;EACf,CAAC;;;;;;;;;;;;;;;ACDJ,MAAa,yBAAyB,OACpC,EAAE,aACF,SAASC,4CAAkB,KACxB;CACH,MAAM,kBAAkB,OAAO;AAQ/B,KAAI,CANwB,iBAAiB,UAAU,KAAK,SAAS,MAClE,WAAW,OAAO,WAAW,aAAa,OAAO,SACnD,CAKC,QAAO;AAMT,KAH4B,iBAAiB,UAAU,KAAK,SAI1D,QAAO;AAMT,SAHmB,MAAM,cAAc,OAAO,EAG5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInstrumentation.d.ts","sourceRoot":"","sources":["../../../../src/services/instrumentation/createInstrumentation/createInstrumentation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,
|
|
1
|
+
{"version":3,"file":"createInstrumentation.d.ts","sourceRoot":"","sources":["../../../../src/services/instrumentation/createInstrumentation/createInstrumentation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAGtB,MAAM,0BAA0B,CAAC;AAElC,KAAK,2BAA2B,GAAG;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACzC,CAAC;AAQF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,8BAE/B,2BAA2B,KAAQ,eAyBrC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the session ID (`sid` claim) from a JWT token string.
|
|
3
|
+
*
|
|
4
|
+
* Decodes the base64url-encoded payload segment of the token and reads the
|
|
5
|
+
* `sid` field. This is used to correlate instrumentation events with the
|
|
6
|
+
* authenticated session, without ever forwarding the full token.
|
|
7
|
+
*
|
|
8
|
+
* Returns `null` when no token is present, when the token is malformed, or
|
|
9
|
+
* when the payload does not contain a `sid` claim.
|
|
10
|
+
*/
|
|
11
|
+
export declare const extractSessionId: (token: string) => string | null;
|
|
12
|
+
//# sourceMappingURL=extractSessionId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractSessionId.d.ts","sourceRoot":"","sources":["../../../../src/services/instrumentation/extractSessionId/extractSessionId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MAAM,GAAG,IASzD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalises the raw positional arguments of an instrumented function call
|
|
3
|
+
* into a flat `Record<string, unknown>` suitable for structured logging.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this is needed
|
|
6
|
+
*
|
|
7
|
+
* Instrumented functions are wrapped with `(...args: unknown[])`, so their
|
|
8
|
+
* parameters arrive as an array. Logging a raw array loses the semantic names
|
|
9
|
+
* of each argument. This function recovers a named representation:
|
|
10
|
+
*
|
|
11
|
+
* - **No arguments** → `{}`
|
|
12
|
+
* - **Single plain-object argument** → that object is returned as-is, because
|
|
13
|
+
* SDK functions follow the single-object-parameter convention, so the object
|
|
14
|
+
* already carries named keys (`{ amount, to }`, etc.).
|
|
15
|
+
* - **Everything else** (multiple args, a single primitive, a single array) →
|
|
16
|
+
* each value is indexed as `arg0`, `arg1`, …
|
|
17
|
+
*
|
|
18
|
+
* ## Why arrays are NOT treated as plain objects
|
|
19
|
+
*
|
|
20
|
+
* `typeof [] === 'object'` and `[] !== null`, so without the `Array.isArray`
|
|
21
|
+
* guard a single-array argument would be returned as-is. That would produce
|
|
22
|
+
* an object with numeric string keys (`{ '0': ..., '1': ... }`), which is
|
|
23
|
+
* misleading and inconsistent with how multi-arg calls are handled. Instead,
|
|
24
|
+
* arrays fall through to the indexed `arg0` path.
|
|
25
|
+
*/
|
|
26
|
+
export declare const extractParams: (args: unknown[]) => Record<string, unknown>;
|
|
27
|
+
//# sourceMappingURL=extractParams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractParams.d.ts","sourceRoot":"","sources":["../../../../../src/services/instrumentation/instrumentFunction/extractParams/extractParams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,aAAa,SAAU,OAAO,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAuBrE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/instrumentation/instrumentFunction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { DynamicCore } from '../../../client/core/types/DynamicCore';
|
|
2
|
+
type InstrumentFunctionParams<T extends (...args: unknown[]) => unknown> = {
|
|
3
|
+
/** The original function to wrap. */
|
|
4
|
+
fn: T;
|
|
5
|
+
/** Human-readable name recorded in every emitted event. */
|
|
6
|
+
functionName: string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the current `DynamicCore` instance, or `undefined` when the SDK
|
|
9
|
+
* has not yet been initialised. Instrumentation is skipped when this returns
|
|
10
|
+
* `undefined` or when `core.instrumentation.config.enabled` is `false`.
|
|
11
|
+
*/
|
|
12
|
+
getCore: () => DynamicCore | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* When `true`, every field in `parameters` and `resolvedValue` is replaced
|
|
15
|
+
* with `"[redacted]"` regardless of `piiFields`. Use this for functions
|
|
16
|
+
* whose arguments are inherently sensitive (e.g., signing, authentication).
|
|
17
|
+
*/
|
|
18
|
+
redactAll?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Wraps a function so that each invocation emits a structured
|
|
22
|
+
* `FunctionInstrumentationEvent` at three lifecycle points:
|
|
23
|
+
*
|
|
24
|
+
* - **started** — immediately before the function body executes, with the
|
|
25
|
+
* PII-scrubbed call parameters.
|
|
26
|
+
* - **resolved** — after the function (or its returned Promise) settles
|
|
27
|
+
* successfully, with the PII-scrubbed return value.
|
|
28
|
+
* - **rejected** — if the function throws synchronously or its returned
|
|
29
|
+
* Promise rejects.
|
|
30
|
+
*
|
|
31
|
+
* The original return value (or thrown error) is always forwarded to the
|
|
32
|
+
* caller unchanged — instrumentation is purely observational.
|
|
33
|
+
*
|
|
34
|
+
* ## Usage
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const transfer = instrumentFunction({
|
|
38
|
+
* fn: rawTransfer,
|
|
39
|
+
* functionName: 'transfer',
|
|
40
|
+
* getCore: () => core,
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // When called, three events are emitted automatically:
|
|
44
|
+
* await transfer({ amount: 1, to: '0xabc' });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* ## How functions are wrapped
|
|
48
|
+
*
|
|
49
|
+
* `instrumentFunction` is not called manually in application code. Instead,
|
|
50
|
+
* the esbuild instrumentation plugin (`tools/instrumentation-plugin`) injects
|
|
51
|
+
* it at build time: any exported function annotated with `@instrumented` in its
|
|
52
|
+
* JSDoc is automatically wrapped by the plugin during the build step.
|
|
53
|
+
* The plugin strips the original `export`, renames the function, and re-exports
|
|
54
|
+
* it under the original name via `instrumentFunction(...)` — so the public API
|
|
55
|
+
* is unchanged and no call sites need to be updated.
|
|
56
|
+
*
|
|
57
|
+
* ## Opting out
|
|
58
|
+
*
|
|
59
|
+
* Instrumentation is skipped entirely when:
|
|
60
|
+
* - `getCore()` returns `undefined` (SDK not initialised), or
|
|
61
|
+
* - `core.instrumentation.config.enabled` is `false`.
|
|
62
|
+
*
|
|
63
|
+
* In both cases the original function is called directly with no overhead.
|
|
64
|
+
*
|
|
65
|
+
* ## PII scrubbing
|
|
66
|
+
*
|
|
67
|
+
* All string values whose key appears in `piiFields` are replaced with
|
|
68
|
+
* `"[redacted]"` before events are emitted. Pass `redactAll: true` to redact
|
|
69
|
+
* every field, regardless of key name.
|
|
70
|
+
*/
|
|
71
|
+
export declare const instrumentFunction: <T extends (...args: unknown[]) => unknown>({ fn, functionName, getCore, redactAll, }: InstrumentFunctionParams<T>) => T;
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=instrumentFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentFunction.d.ts","sourceRoot":"","sources":["../../../../src/services/instrumentation/instrumentFunction/instrumentFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAQ1E,KAAK,wBAAwB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,IAAI;IACzE,qCAAqC;IACrC,EAAE,EAAE,CAAC,CAAC;IACN,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,OAAO,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;IACvC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,6CAKzE,wBAAwB,CAAC,CAAC,CAAC,KAAG,CAuFhC,CAAC"}
|
package/dist/services/instrumentation/instrumentFunction/scrubResolvedValue/scrubResolvedValue.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ScrubResolvedValueParams = {
|
|
2
|
+
piiFields: string[];
|
|
3
|
+
redactAll?: boolean;
|
|
4
|
+
value: unknown;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Scrubs a resolved return value of any type before logging it.
|
|
8
|
+
* Routes through `scrubParameters` by wrapping the value so that strings,
|
|
9
|
+
* arrays, Dates, Errors, and all other types are handled identically to
|
|
10
|
+
* nested object fields.
|
|
11
|
+
*/
|
|
12
|
+
export declare const scrubResolvedValue: ({ piiFields, redactAll, value, }: ScrubResolvedValueParams) => unknown;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=scrubResolvedValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrubResolvedValue.d.ts","sourceRoot":"","sources":["../../../../../src/services/instrumentation/instrumentFunction/scrubResolvedValue/scrubResolvedValue.ts"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG;IAC9B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,qCAI5B,wBAAwB,KAAG,OAKnB,CAAC"}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
export type InstrumentationEventPhase = 'started' | 'resolved' | 'rejected';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* a function call (started, resolved, rejected).
|
|
3
|
+
* Common fields shared by all instrumentation events.
|
|
5
4
|
*
|
|
6
5
|
* All string values that match piiFields are redacted before this event is
|
|
7
6
|
* constructed, so it is safe to forward to an external transport.
|
|
8
7
|
*/
|
|
9
8
|
export type InstrumentationEvent = {
|
|
10
|
-
callerChain: string[];
|
|
11
9
|
environmentId: string;
|
|
12
|
-
functionName: string;
|
|
13
|
-
isExternalCall: boolean;
|
|
14
10
|
parameters: Record<string, unknown>;
|
|
15
|
-
phase: InstrumentationEventPhase;
|
|
16
|
-
rejectedError?: Error;
|
|
17
|
-
resolvedValue?: unknown;
|
|
18
11
|
sdkSessionId: string;
|
|
19
12
|
sdkVersion: string;
|
|
20
13
|
timestamp: string;
|
|
@@ -22,6 +15,17 @@ export type InstrumentationEvent = {
|
|
|
22
15
|
userAgent: string;
|
|
23
16
|
userId: string | null;
|
|
24
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* A telemetry record emitted by instrumentFunction for each phase of a
|
|
20
|
+
* function call (started, resolved, rejected). Extends InstrumentationEvent
|
|
21
|
+
* with function-execution-specific fields.
|
|
22
|
+
*/
|
|
23
|
+
export type FunctionInstrumentationEvent = InstrumentationEvent & {
|
|
24
|
+
functionName: string;
|
|
25
|
+
phase: InstrumentationEventPhase;
|
|
26
|
+
rejectedError?: Error;
|
|
27
|
+
resolvedValue?: unknown;
|
|
28
|
+
};
|
|
25
29
|
export type InstrumentationConfig = {
|
|
26
30
|
enabled: boolean;
|
|
27
31
|
piiFields: string[];
|
|
@@ -38,6 +42,7 @@ export type InstrumentationTransport = {
|
|
|
38
42
|
export type Instrumentation = {
|
|
39
43
|
config: InstrumentationConfig;
|
|
40
44
|
log: (event: InstrumentationEvent) => void;
|
|
45
|
+
logFunction: (event: FunctionInstrumentationEvent) => void;
|
|
41
46
|
setEnabled: (enabled: boolean) => void;
|
|
42
47
|
setTransport: (transport: InstrumentationTransport) => void;
|
|
43
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.types.d.ts","sourceRoot":"","sources":["../../../src/services/instrumentation/instrumentation.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE5E
|
|
1
|
+
{"version":3,"file":"instrumentation.types.d.ts","sourceRoot":"","sources":["../../../src/services/instrumentation/instrumentation.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG,oBAAoB,GAAG;IAChE,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,yBAAyB,CAAC;IACjC,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,wBAAwB,GAAG;IACrC,GAAG,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,qBAAqB,CAAC;IAC9B,GAAG,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC3C,WAAW,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,IAAI,CAAC;IAC3D,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,YAAY,EAAE,CAAC,SAAS,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAC7D,CAAC"}
|
package/dist/services/instrumentation/transports/createDynamicTransport/createDynamicTransport.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Fetch } from '../../../fetch';
|
|
2
|
+
import type { InstrumentationTransport } from '../../instrumentation.types';
|
|
3
|
+
type CreateDynamicTransportParams = {
|
|
4
|
+
environmentId: string;
|
|
5
|
+
fetch: Fetch;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a batched transport that ships instrumentation events to Dynamic's
|
|
9
|
+
* log ingestion endpoint.
|
|
10
|
+
*
|
|
11
|
+
* Events are queued synchronously and flushed as a single HTTP batch in the
|
|
12
|
+
* next microtask (via queueMicrotask). Multiple log() calls within the same
|
|
13
|
+
* synchronous tick are coalesced into one request, avoiding a round-trip per
|
|
14
|
+
* event.
|
|
15
|
+
*
|
|
16
|
+
* Fetch errors are swallowed to prevent an instrumentation failure from
|
|
17
|
+
* triggering another instrumentation event and causing an infinite loop.
|
|
18
|
+
*
|
|
19
|
+
* Works in both browser and SSR environments — fetch is injected and
|
|
20
|
+
* queueMicrotask is available in Node.js >= 11.
|
|
21
|
+
*/
|
|
22
|
+
export declare const createDynamicTransport: (params: CreateDynamicTransportParams) => InstrumentationTransport;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=createDynamicTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDynamicTransport.d.ts","sourceRoot":"","sources":["../../../../../src/services/instrumentation/transports/createDynamicTransport/createDynamicTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AAIrC,KAAK,4BAA4B,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,WACzB,4BAA4B,KACnC,wBAkCF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/services/instrumentation/transports/createDynamicTransport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|