@zapier/zapier-sdk 0.15.4 → 0.15.9
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/CHANGELOG.md +30 -0
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +14 -4
- package/dist/api/auth.test.d.ts +2 -0
- package/dist/api/auth.test.d.ts.map +1 -0
- package/dist/api/auth.test.js +220 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +18 -32
- package/dist/api/client.methods.test.d.ts +2 -0
- package/dist/api/client.methods.test.d.ts.map +1 -0
- package/dist/api/client.methods.test.js +158 -0
- package/dist/api/client.test.js +27 -11
- package/dist/api/router.d.ts +16 -0
- package/dist/api/router.d.ts.map +1 -0
- package/dist/api/router.js +37 -0
- package/dist/api/router.test.d.ts +2 -0
- package/dist/api/router.test.d.ts.map +1 -0
- package/dist/api/router.test.js +109 -0
- package/dist/auth.d.ts +15 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +25 -0
- package/dist/index.cjs +247 -74
- package/dist/index.d.mts +402 -241
- package/dist/index.mjs +247 -75
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +9 -5
- package/dist/plugins/eventEmission/index.test.js +161 -0
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +2 -4
- package/dist/plugins/getAction/index.test.js +26 -3
- package/dist/plugins/getAuthentication/index.d.ts +2 -5
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +3 -24
- package/dist/plugins/getAuthentication/index.test.js +32 -144
- package/dist/plugins/getAuthentication/schemas.d.ts +4 -13
- package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/schemas.js +1 -11
- package/dist/sdk.d.ts +1 -1
- package/dist/temporary-internal-core/handlers/getAuthentication.d.ts +94 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.js +68 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts +2 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.js +248 -0
- package/dist/temporary-internal-core/handlers/listApps.js +1 -1
- package/dist/temporary-internal-core/index.d.ts +2 -0
- package/dist/temporary-internal-core/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/index.js +2 -0
- package/dist/temporary-internal-core/schemas/authentications/index.d.ts +454 -0
- package/dist/temporary-internal-core/schemas/authentications/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/authentications/index.js +96 -0
- package/dist/temporary-internal-core/schemas/errors/index.d.ts +139 -0
- package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/errors/index.js +129 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -20
- package/dist/temporary-internal-core/utils/app-locators.d.ts.map +1 -1
- package/dist/temporary-internal-core/utils/app-locators.js +1 -45
- package/dist/temporary-internal-core/utils/string-utils.d.ts +28 -0
- package/dist/temporary-internal-core/utils/string-utils.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/string-utils.js +52 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts +14 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -1
- package/dist/temporary-internal-core/utils/transformations.js +37 -1
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all Zapier SDK errors
|
|
3
|
+
* Use instanceof ZapierError to check if an error is from the SDK
|
|
4
|
+
*/
|
|
5
|
+
export class ZapierError extends Error {
|
|
6
|
+
constructor(message, options = {}) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.statusCode = options.statusCode;
|
|
9
|
+
this.errors = options.errors;
|
|
10
|
+
this.cause = options.cause;
|
|
11
|
+
this.response = options.response;
|
|
12
|
+
// Maintain proper prototype chain for instanceof checks
|
|
13
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when API requests fail
|
|
18
|
+
*/
|
|
19
|
+
export class ZapierApiError extends ZapierError {
|
|
20
|
+
constructor(message, options = {}) {
|
|
21
|
+
super(message, options);
|
|
22
|
+
this.name = "ZapierApiError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when an app is not found
|
|
27
|
+
*/
|
|
28
|
+
export class ZapierAppNotFoundError extends ZapierError {
|
|
29
|
+
constructor(message, options = {}) {
|
|
30
|
+
super(message, options);
|
|
31
|
+
this.name = "ZapierAppNotFoundError";
|
|
32
|
+
this.appKey = options.appKey;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when validation fails (e.g., invalid parameters)
|
|
37
|
+
*/
|
|
38
|
+
export class ZapierValidationError extends ZapierError {
|
|
39
|
+
constructor(message, options = {}) {
|
|
40
|
+
super(message, options);
|
|
41
|
+
this.name = "ZapierValidationError";
|
|
42
|
+
this.details = options.details;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Error for unrecognized/unknown errors that get wrapped by safe functions
|
|
47
|
+
*/
|
|
48
|
+
export class ZapierUnknownError extends ZapierError {
|
|
49
|
+
constructor(message, options = {}) {
|
|
50
|
+
super(message, options);
|
|
51
|
+
this.name = "ZapierUnknownError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Error thrown for authentication and authorization failures (401/403)
|
|
56
|
+
*/
|
|
57
|
+
export class ZapierAuthenticationError extends ZapierError {
|
|
58
|
+
constructor(message, options = {}) {
|
|
59
|
+
super(message, options);
|
|
60
|
+
this.name = "ZapierAuthenticationError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Error thrown when a requested resource is not found
|
|
65
|
+
*/
|
|
66
|
+
export class ZapierResourceNotFoundError extends ZapierError {
|
|
67
|
+
constructor(message, options = {}) {
|
|
68
|
+
super(message, options);
|
|
69
|
+
this.name = "ZapierResourceNotFoundError";
|
|
70
|
+
this.resourceType = options.resourceType;
|
|
71
|
+
this.resourceId = options.resourceId;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error thrown when required app or implementation configuration is missing
|
|
76
|
+
*/
|
|
77
|
+
export class ZapierConfigurationError extends ZapierError {
|
|
78
|
+
constructor(message, options = {}) {
|
|
79
|
+
super(message, options);
|
|
80
|
+
this.name = "ZapierConfigurationError";
|
|
81
|
+
this.configType = options.configType;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Error thrown when code bundling or compilation fails
|
|
86
|
+
*/
|
|
87
|
+
export class ZapierBundleError extends ZapierError {
|
|
88
|
+
constructor(message, options = {}) {
|
|
89
|
+
super(message, options);
|
|
90
|
+
this.name = "ZapierBundleError";
|
|
91
|
+
this.buildErrors = options.buildErrors;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Error thrown when operations timeout or exceed retry limits
|
|
96
|
+
*/
|
|
97
|
+
export class ZapierTimeoutError extends ZapierError {
|
|
98
|
+
constructor(message, options = {}) {
|
|
99
|
+
super(message, options);
|
|
100
|
+
this.name = "ZapierTimeoutError";
|
|
101
|
+
this.attempts = options.attempts;
|
|
102
|
+
this.maxAttempts = options.maxAttempts;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Error thrown when action execution fails due to errors returned from the third-party service
|
|
107
|
+
* This happens when the Actions API returns a 200 status but includes errors in the response
|
|
108
|
+
*/
|
|
109
|
+
export class ZapierActionError extends ZapierError {
|
|
110
|
+
constructor(message, options = {}) {
|
|
111
|
+
super(message, options);
|
|
112
|
+
this.name = "ZapierActionError";
|
|
113
|
+
this.appKey = options.appKey;
|
|
114
|
+
this.actionKey = options.actionKey;
|
|
115
|
+
}
|
|
116
|
+
// Legacy accessor for backward compatibility
|
|
117
|
+
get actionErrors() {
|
|
118
|
+
return this.errors;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Error thrown when a resource is not found (404)
|
|
123
|
+
*/
|
|
124
|
+
export class ZapierNotFoundError extends ZapierError {
|
|
125
|
+
constructor(message, options = {}) {
|
|
126
|
+
super(message, options);
|
|
127
|
+
this.name = "ZapierNotFoundError";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -19,26 +19,6 @@ export interface AppLocator {
|
|
|
19
19
|
export interface ResolvedAppLocator extends AppLocator {
|
|
20
20
|
implementationName: string;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Checks if a string is a valid slug (kebab-case)
|
|
24
|
-
*/
|
|
25
|
-
export declare function isSlug(slug: string): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if a string is a valid snake_case slug
|
|
28
|
-
*/
|
|
29
|
-
export declare function isSnakeCasedSlug(slug: string): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Converts snake_case to kebab-case
|
|
32
|
-
*/
|
|
33
|
-
export declare function dashifySnakeCasedSlug(slug: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Checks if a string is a UUID
|
|
36
|
-
*/
|
|
37
|
-
export declare function isUuid(appKey: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Splits a versioned key into base key and version
|
|
40
|
-
*/
|
|
41
|
-
export declare function splitVersionedKey(versionedKey: string): [string, string | undefined];
|
|
42
22
|
/**
|
|
43
23
|
* Converts an app key to an app locator structure
|
|
44
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-locators.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/utils/app-locators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"app-locators.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/utils/app-locators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,UAAU;IACpD,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAqBvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,kBAAkB,GAAG,MAAM,CAEzE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,UAAU,GACrB,UAAU,IAAI,kBAAkB,CAElC"}
|
|
@@ -4,51 +4,7 @@
|
|
|
4
4
|
* These utilities handle the mapping between user-friendly app identifiers
|
|
5
5
|
* (slugs like "slack") and internal implementation IDs (like "SlackCLIAPI@1.0.0")
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
* Checks if a string is a valid slug (kebab-case)
|
|
9
|
-
*/
|
|
10
|
-
export function isSlug(slug) {
|
|
11
|
-
return !!slug.match(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Checks if a string is a valid snake_case slug
|
|
15
|
-
*/
|
|
16
|
-
export function isSnakeCasedSlug(slug) {
|
|
17
|
-
if (slug.match(/^_[0-9]/)) {
|
|
18
|
-
slug = slug.slice(1);
|
|
19
|
-
}
|
|
20
|
-
return !!slug.match(/^[a-z0-9]+(?:_[a-z0-9]+)*$/);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Converts snake_case to kebab-case
|
|
24
|
-
*/
|
|
25
|
-
export function dashifySnakeCasedSlug(slug) {
|
|
26
|
-
if (!isSnakeCasedSlug(slug)) {
|
|
27
|
-
return slug;
|
|
28
|
-
}
|
|
29
|
-
if (slug.startsWith("_")) {
|
|
30
|
-
slug = slug.slice(1);
|
|
31
|
-
}
|
|
32
|
-
return slug.replace(/_/g, "-");
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Checks if a string is a UUID
|
|
36
|
-
*/
|
|
37
|
-
export function isUuid(appKey) {
|
|
38
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(appKey);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Splits a versioned key into base key and version
|
|
42
|
-
*/
|
|
43
|
-
export function splitVersionedKey(versionedKey) {
|
|
44
|
-
const parts = versionedKey.split("@");
|
|
45
|
-
if (parts.length >= 2) {
|
|
46
|
-
const baseKey = parts[0];
|
|
47
|
-
const version = parts.slice(1).join("@");
|
|
48
|
-
return [baseKey, version];
|
|
49
|
-
}
|
|
50
|
-
return [versionedKey, undefined];
|
|
51
|
-
}
|
|
7
|
+
import { dashifySnakeCasedSlug, isSlug, isSnakeCasedSlug, isUuid, splitVersionedKey, } from "./string-utils";
|
|
52
8
|
/**
|
|
53
9
|
* Converts an app key to an app locator structure
|
|
54
10
|
*/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a versioned key to extract the base key and version
|
|
3
|
+
*
|
|
4
|
+
* @param versionedKey - Versioned key in format "KeyName@version" (e.g., "SlackCLIAPI@1.21.1")
|
|
5
|
+
* @returns Tuple of [baseKey, version] or [versionedKey, undefined] if no @ symbol
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* splitVersionedKey("SlackCLIAPI@1.21.1") // ["SlackCLIAPI", "1.21.1"]
|
|
9
|
+
* splitVersionedKey("SomeAPI") // ["SomeAPI", undefined]
|
|
10
|
+
*/
|
|
11
|
+
export declare function splitVersionedKey(versionedKey: string): [string, string | undefined];
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a string is a valid slug (kebab-case)
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSlug(slug: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a string is a valid snake_case slug
|
|
18
|
+
*/
|
|
19
|
+
export declare function isSnakeCasedSlug(slug: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Converts snake_case to kebab-case
|
|
22
|
+
*/
|
|
23
|
+
export declare function dashifySnakeCasedSlug(slug: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if a string is a UUID
|
|
26
|
+
*/
|
|
27
|
+
export declare function isUuid(appKey: string): boolean;
|
|
28
|
+
//# sourceMappingURL=string-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/utils/string-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GACnB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAQ9B;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKtD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAU1D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAI9C"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a versioned key to extract the base key and version
|
|
3
|
+
*
|
|
4
|
+
* @param versionedKey - Versioned key in format "KeyName@version" (e.g., "SlackCLIAPI@1.21.1")
|
|
5
|
+
* @returns Tuple of [baseKey, version] or [versionedKey, undefined] if no @ symbol
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* splitVersionedKey("SlackCLIAPI@1.21.1") // ["SlackCLIAPI", "1.21.1"]
|
|
9
|
+
* splitVersionedKey("SomeAPI") // ["SomeAPI", undefined]
|
|
10
|
+
*/
|
|
11
|
+
export function splitVersionedKey(versionedKey) {
|
|
12
|
+
const parts = versionedKey.split("@");
|
|
13
|
+
if (parts.length >= 2) {
|
|
14
|
+
const baseKey = parts[0];
|
|
15
|
+
const version = parts.slice(1).join("@"); // Handle edge case of multiple @ symbols
|
|
16
|
+
return [baseKey, version];
|
|
17
|
+
}
|
|
18
|
+
return [versionedKey, undefined];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a string is a valid slug (kebab-case)
|
|
22
|
+
*/
|
|
23
|
+
export function isSlug(slug) {
|
|
24
|
+
return !!slug.match(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a string is a valid snake_case slug
|
|
28
|
+
*/
|
|
29
|
+
export function isSnakeCasedSlug(slug) {
|
|
30
|
+
if (slug.match(/^_[0-9]/)) {
|
|
31
|
+
slug = slug.slice(1);
|
|
32
|
+
}
|
|
33
|
+
return !!slug.match(/^[a-z0-9]+(?:_[a-z0-9]+)*$/);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Converts snake_case to kebab-case
|
|
37
|
+
*/
|
|
38
|
+
export function dashifySnakeCasedSlug(slug) {
|
|
39
|
+
if (!isSnakeCasedSlug(slug)) {
|
|
40
|
+
return slug;
|
|
41
|
+
}
|
|
42
|
+
if (slug.startsWith("_")) {
|
|
43
|
+
slug = slug.slice(1);
|
|
44
|
+
}
|
|
45
|
+
return slug.replace(/_/g, "-");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a string is a UUID
|
|
49
|
+
*/
|
|
50
|
+
export function isUuid(appKey) {
|
|
51
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(appKey);
|
|
52
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ImplementationMeta } from "../schemas/implementations";
|
|
7
7
|
import type { AppItem } from "../schemas/apps";
|
|
8
|
+
import { type Authentication, type AuthenticationItem } from "../schemas/authentications";
|
|
8
9
|
/**
|
|
9
10
|
* Transforms ImplementationMeta from internal API to AppItem for SDK responses
|
|
10
11
|
*/
|
|
@@ -15,4 +16,17 @@ export declare function transformImplementationMetaToAppItem(implementationMeta:
|
|
|
15
16
|
export declare function extractPaginationCursor(response: {
|
|
16
17
|
next?: string | null;
|
|
17
18
|
}): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Converts an API Authentication to an AuthenticationItem with normalized field names
|
|
21
|
+
*
|
|
22
|
+
* @param auth - Raw Authentication from API
|
|
23
|
+
* @param options - Additional fields to include
|
|
24
|
+
* @param options.app_key - selected_api from implementations endpoint
|
|
25
|
+
* @param options.app_version - Version extracted from selected_api
|
|
26
|
+
* @returns Normalized AuthenticationItem
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeAuthenticationItem(auth: Authentication, options?: {
|
|
29
|
+
app_key?: string;
|
|
30
|
+
app_version?: string;
|
|
31
|
+
}): AuthenticationItem;
|
|
18
32
|
//# sourceMappingURL=transformations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformations.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/utils/transformations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"transformations.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/utils/transformations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,wBAAgB,oCAAoC,CAClD,kBAAkB,EAAE,kBAAkB,GACrC,OAAO,CAYT;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE;IAChD,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,GAAG,MAAM,GAAG,SAAS,CAYrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GACvD,kBAAkB,CAqCpB"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* These will move to SDK API server as part of the response transformation layer
|
|
5
5
|
*/
|
|
6
|
-
import { splitVersionedKey } from "./
|
|
6
|
+
import { splitVersionedKey } from "./string-utils";
|
|
7
7
|
/**
|
|
8
8
|
* Transforms ImplementationMeta from internal API to AppItem for SDK responses
|
|
9
9
|
*/
|
|
@@ -34,3 +34,39 @@ export function extractPaginationCursor(response) {
|
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts an API Authentication to an AuthenticationItem with normalized field names
|
|
39
|
+
*
|
|
40
|
+
* @param auth - Raw Authentication from API
|
|
41
|
+
* @param options - Additional fields to include
|
|
42
|
+
* @param options.app_key - selected_api from implementations endpoint
|
|
43
|
+
* @param options.app_version - Version extracted from selected_api
|
|
44
|
+
* @returns Normalized AuthenticationItem
|
|
45
|
+
*/
|
|
46
|
+
export function normalizeAuthenticationItem(auth, options = {}) {
|
|
47
|
+
// Extract app key and version from selected_api if not provided
|
|
48
|
+
let appKey = options.app_key;
|
|
49
|
+
let appVersion = options.app_version;
|
|
50
|
+
if (auth.selected_api) {
|
|
51
|
+
const [extractedAppKey, extractedVersion] = splitVersionedKey(auth.selected_api);
|
|
52
|
+
// Use extracted app key if not provided in options
|
|
53
|
+
if (!appKey) {
|
|
54
|
+
appKey = extractedAppKey;
|
|
55
|
+
}
|
|
56
|
+
// Use extracted version if not provided in options
|
|
57
|
+
if (!appVersion) {
|
|
58
|
+
appVersion = extractedVersion;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const { selected_api: selectedApi, customuser_id: userId, ...restOfAuth } = auth;
|
|
62
|
+
return {
|
|
63
|
+
...restOfAuth, // Pass through all other API response fields except selected_api
|
|
64
|
+
implementation_id: selectedApi, // Rename selected_api to implementation_id
|
|
65
|
+
title: auth.title || auth.label || undefined, // Coerce title from label if missing
|
|
66
|
+
is_expired: auth.is_stale, // Map is_stale to is_expired
|
|
67
|
+
expired_at: auth.marked_stale_at, // Map marked_stale_at to expired_at
|
|
68
|
+
app_key: appKey, // App key from implementations endpoint or parsed from selected_api
|
|
69
|
+
app_version: appVersion, // Version from selected_api or provided
|
|
70
|
+
user_id: userId, // Map customuser_id to user_id
|
|
71
|
+
};
|
|
72
|
+
}
|