@glideidentity/glide-be-sdk-node 2.0.1

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/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (c) Glide Identity Inc.
2
+
3
+ Use of this SDK is permitted solely to enable your use of Glide Identity Inc.'s
4
+ services. All other use of this SDK is prohibited. All other rights are reserved.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @glideidentity/glide-be-sdk-node
2
+
3
+ Glide SDK for Node.js — carrier-based phone verification.
4
+
5
+ **Documentation**: https://docs.glideidentity.com
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @glideidentity/glide-be-sdk-node
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { GlideClient, UseCase } from '@glideidentity/glide-be-sdk-node';
17
+
18
+ const client = new GlideClient({
19
+ clientId: process.env.GLIDE_CLIENT_ID,
20
+ clientSecret: process.env.GLIDE_CLIENT_SECRET
21
+ });
22
+
23
+ // Prepare authentication
24
+ const response = await client.magicalAuth.prepare({
25
+ use_case: UseCase.VERIFY_PHONE_NUMBER,
26
+ phone_number: '+14155551234'
27
+ });
28
+
29
+ // Process credential from browser
30
+ const result = await client.magicalAuth.verifyPhoneNumber({
31
+ session: response.session,
32
+ credential: credentialFromBrowser
33
+ });
34
+
35
+ console.log(result.verified); // true
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ ```typescript
41
+ const client = new GlideClient({
42
+ clientId: 'your-client-id', // Required (or set GLIDE_CLIENT_ID env var)
43
+ clientSecret: 'your-secret', // Required (or set GLIDE_CLIENT_SECRET env var)
44
+ baseUrl: 'https://api.glideidentity.app', // Optional, defaults to production
45
+ logLevel: LogLevel.INFO, // DEBUG | INFO | WARN | ERROR
46
+ logFormat: 'text', // 'text' | 'json'
47
+ tokenRefreshBuffer: 60, // Seconds before token expiry to refresh (default: 60)
48
+ });
49
+ ```
50
+
51
+ ### Environment Variables
52
+
53
+ Configuration can also be set via environment variables:
54
+
55
+ | Variable | Default | Description |
56
+ |----------|---------|-------------|
57
+ | `GLIDE_CLIENT_ID` | — | OAuth2 client ID (required if not set programmatically) |
58
+ | `GLIDE_CLIENT_SECRET` | — | OAuth2 client secret (required if not set programmatically) |
59
+ | `GLIDE_API_BASE_URL` | `https://api.glideidentity.app` | API endpoint |
60
+ | `GLIDE_LOG_LEVEL` | `info` | Log level: debug, info, warn, error |
61
+
62
+ Programmatic settings take precedence over environment variables.
63
+
64
+ ## Error Handling
65
+
66
+ ```typescript
67
+ import { MagicalAuthError, ErrorCode } from '@glideidentity/glide-be-sdk-node';
68
+
69
+ try {
70
+ await client.magicalAuth.prepare(request);
71
+ } catch (error) {
72
+ if (error instanceof MagicalAuthError) {
73
+ if (error.is(ErrorCode.CARRIER_NOT_ELIGIBLE)) {
74
+ // Handle unsupported carrier
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Types Only
81
+
82
+ For types and constants without HTTP client:
83
+
84
+ ```bash
85
+ npm install @glideidentity/glide-be-sdk-node-core
86
+ ```
87
+
88
+ ## License
89
+
90
+ Copyright (c) Glide Identity Inc.
@@ -0,0 +1,58 @@
1
+ import { ErrorCode } from '@glideidentity/glide-be-sdk-node-core';
2
+ import type { ErrorCodeType } from '@glideidentity/glide-be-sdk-node-core';
3
+ export { ErrorCode };
4
+ export type { ErrorCodeType };
5
+ /**
6
+ * Error thrown by Magical Auth operations.
7
+ *
8
+ * @example
9
+ * try {
10
+ * await client.magicalAuth.prepare(request);
11
+ * } catch (error) {
12
+ * if (error instanceof MagicalAuthError) {
13
+ * console.log(error.code, error.status);
14
+ * }
15
+ * }
16
+ */
17
+ export declare class MagicalAuthError extends Error {
18
+ readonly name = "MagicalAuthError";
19
+ /** Error code (e.g., CARRIER_NOT_ELIGIBLE). */
20
+ readonly code: string;
21
+ /** HTTP status code. */
22
+ readonly status: number;
23
+ /** Request ID for debugging. */
24
+ readonly requestId?: string;
25
+ readonly timestamp?: string;
26
+ readonly traceId?: string;
27
+ readonly spanId?: string;
28
+ readonly service?: string;
29
+ readonly details?: Record<string, unknown>;
30
+ constructor(errorResponse: {
31
+ code?: string;
32
+ message?: string;
33
+ status?: number;
34
+ request_id?: string;
35
+ requestId?: string;
36
+ timestamp?: string;
37
+ trace_id?: string;
38
+ traceId?: string;
39
+ span_id?: string;
40
+ spanId?: string;
41
+ service?: string;
42
+ details?: Record<string, unknown>;
43
+ });
44
+ /** Checks if error matches the specified code. */
45
+ is(code: ErrorCodeType): boolean;
46
+ toJSON(): {
47
+ code: string;
48
+ message: string;
49
+ status: number;
50
+ request_id: string | undefined;
51
+ timestamp: string | undefined;
52
+ trace_id: string | undefined;
53
+ span_id: string | undefined;
54
+ service: string | undefined;
55
+ details: Record<string, unknown> | undefined;
56
+ };
57
+ }
58
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACvC,SAAgB,IAAI,sBAAsB;IAC1C,+CAA+C;IAC/C,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,wBAAwB;IACxB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,gCAAgC;IAChC,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjC,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEtC,aAAa,EAAE;QACvB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC;IAsBD,kDAAkD;IAClD,EAAE,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAIhC,MAAM;;;;;;;;;;;CAqBT"}
package/dist/errors.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagicalAuthError = exports.ErrorCode = void 0;
4
+ const glide_be_sdk_node_core_1 = require("@glideidentity/glide-be-sdk-node-core");
5
+ Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return glide_be_sdk_node_core_1.ErrorCode; } });
6
+ /**
7
+ * Error thrown by Magical Auth operations.
8
+ *
9
+ * @example
10
+ * try {
11
+ * await client.magicalAuth.prepare(request);
12
+ * } catch (error) {
13
+ * if (error instanceof MagicalAuthError) {
14
+ * console.log(error.code, error.status);
15
+ * }
16
+ * }
17
+ */
18
+ class MagicalAuthError extends Error {
19
+ constructor(errorResponse) {
20
+ super(errorResponse.message || 'Magical Auth Error');
21
+ this.name = 'MagicalAuthError';
22
+ Object.defineProperty(this, 'stack', {
23
+ enumerable: false,
24
+ configurable: true,
25
+ writable: true,
26
+ value: this.stack
27
+ });
28
+ this.code = errorResponse.code || glide_be_sdk_node_core_1.ErrorCode.INTERNAL_SERVER_ERROR;
29
+ this.status = errorResponse.status ?? 500;
30
+ this.requestId = errorResponse.requestId || errorResponse.request_id;
31
+ this.timestamp = errorResponse.timestamp;
32
+ this.traceId = errorResponse.traceId || errorResponse.trace_id;
33
+ this.spanId = errorResponse.spanId || errorResponse.span_id;
34
+ this.service = errorResponse.service;
35
+ this.details = errorResponse.details;
36
+ Object.setPrototypeOf(this, MagicalAuthError.prototype);
37
+ }
38
+ /** Checks if error matches the specified code. */
39
+ is(code) {
40
+ return this.code === code;
41
+ }
42
+ toJSON() {
43
+ return {
44
+ code: this.code,
45
+ message: this.message,
46
+ status: this.status,
47
+ request_id: this.requestId,
48
+ timestamp: this.timestamp,
49
+ trace_id: this.traceId,
50
+ span_id: this.spanId,
51
+ service: this.service,
52
+ details: this.details
53
+ };
54
+ }
55
+ /** Custom inspect for cleaner console output (Node.js). */
56
+ [Symbol.for('nodejs.util.inspect.custom')]() {
57
+ const props = [`code: '${this.code}'`, `status: ${this.status}`];
58
+ if (this.requestId)
59
+ props.push(`requestId: '${this.requestId}'`);
60
+ if (this.details)
61
+ props.push(`details: ${JSON.stringify(this.details)}`);
62
+ return `MagicalAuthError: ${this.message} { ${props.join(', ')} }`;
63
+ }
64
+ }
65
+ exports.MagicalAuthError = MagicalAuthError;
@@ -0,0 +1,31 @@
1
+ import { GlideSdkSettings } from './types';
2
+ import { MagicalAuth } from './services/magical-auth';
3
+ /**
4
+ * Glide API client.
5
+ *
6
+ * @example
7
+ * const client = new GlideClient({
8
+ * clientId: process.env.GLIDE_CLIENT_ID,
9
+ * clientSecret: process.env.GLIDE_CLIENT_SECRET
10
+ * });
11
+ * const response = await client.magicalAuth.prepare({ use_case: UseCase.VERIFY_PHONE_NUMBER, phone_number: '+14155551234' });
12
+ */
13
+ export declare class GlideClient {
14
+ private settings;
15
+ private logger;
16
+ private oauthClient;
17
+ /** Magical Auth service for phone verification. */
18
+ magicalAuth: MagicalAuth;
19
+ /**
20
+ * Creates a new Glide client.
21
+ * @param settings - Client configuration. Client ID and Client Secret are required.
22
+ * @throws Error if credentials are not provided.
23
+ */
24
+ constructor(settings?: Partial<GlideSdkSettings>);
25
+ /**
26
+ * Clears the cached OAuth token, forcing a refresh on the next API call.
27
+ * Useful for handling token invalidation or testing.
28
+ */
29
+ clearTokenCache(): void;
30
+ }
31
+ //# sourceMappingURL=glide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glide.d.ts","sourceRoot":"","sources":["../src/glide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAQtD;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAe;IAElC,mDAAmD;IAC5C,WAAW,EAAE,WAAW,CAAC;IAEhC;;;;OAIG;gBACS,QAAQ,GAAE,OAAO,CAAC,gBAAgB,CAAM;IA0CpD;;;OAGG;IACH,eAAe,IAAI,IAAI;CAG1B"}
package/dist/glide.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlideClient = void 0;
4
+ const magical_auth_1 = require("./services/magical-auth");
5
+ const oauth_1 = require("./internal/oauth");
6
+ const logger_1 = require("./logger");
7
+ const glide_be_sdk_node_core_1 = require("@glideidentity/glide-be-sdk-node-core");
8
+ const DEFAULT_BASE_URL = 'https://api.glideidentity.app';
9
+ /**
10
+ * Glide API client.
11
+ *
12
+ * @example
13
+ * const client = new GlideClient({
14
+ * clientId: process.env.GLIDE_CLIENT_ID,
15
+ * clientSecret: process.env.GLIDE_CLIENT_SECRET
16
+ * });
17
+ * const response = await client.magicalAuth.prepare({ use_case: UseCase.VERIFY_PHONE_NUMBER, phone_number: '+14155551234' });
18
+ */
19
+ class GlideClient {
20
+ /**
21
+ * Creates a new Glide client.
22
+ * @param settings - Client configuration. Client ID and Client Secret are required.
23
+ * @throws Error if credentials are not provided.
24
+ */
25
+ constructor(settings = {}) {
26
+ const clientId = settings.clientId || process.env.GLIDE_CLIENT_ID || '';
27
+ const clientSecret = settings.clientSecret || process.env.GLIDE_CLIENT_SECRET || '';
28
+ const baseUrl = settings.baseUrl || process.env.GLIDE_API_BASE_URL || DEFAULT_BASE_URL;
29
+ if (!clientId) {
30
+ throw new Error('Client ID is required. Set GLIDE_CLIENT_ID environment variable or pass clientId option');
31
+ }
32
+ if (!clientSecret) {
33
+ throw new Error('Client Secret is required. Set GLIDE_CLIENT_SECRET environment variable or pass clientSecret option');
34
+ }
35
+ this.settings = {
36
+ clientId,
37
+ clientSecret,
38
+ baseUrl,
39
+ logLevel: settings.logLevel,
40
+ logFormat: settings.logFormat,
41
+ logger: settings.logger,
42
+ tokenRefreshBuffer: settings.tokenRefreshBuffer,
43
+ };
44
+ this.logger = settings.logger ?? (0, logger_1.createLogger)(settings.logLevel, settings.logFormat);
45
+ // Initialize OAuth client for token management
46
+ this.oauthClient = new oauth_1.OAuthManager(clientId, clientSecret, baseUrl, this.logger, settings.tokenRefreshBuffer);
47
+ this.logger.info('Glide SDK initialized', {
48
+ version: glide_be_sdk_node_core_1.VERSION,
49
+ baseUrl: this.settings.baseUrl,
50
+ });
51
+ this.magicalAuth = new magical_auth_1.MagicalAuth(this.settings, this.oauthClient, this.logger);
52
+ }
53
+ /**
54
+ * Clears the cached OAuth token, forcing a refresh on the next API call.
55
+ * Useful for handling token invalidation or testing.
56
+ */
57
+ clearTokenCache() {
58
+ this.oauthClient.clearCache();
59
+ }
60
+ }
61
+ exports.GlideClient = GlideClient;
@@ -0,0 +1,12 @@
1
+ export * from '@glideidentity/glide-be-sdk-node-core';
2
+ export type { GlideSdkSettings, LogFormat, TokenResponse, CachedToken } from './types';
3
+ export { GlideClient } from './glide';
4
+ export type { Logger, LogField } from './logger';
5
+ export { LogLevel, createLogger, generateRequestId } from './logger';
6
+ export { MagicalAuthError } from './errors';
7
+ export { validatePhoneNumber, validatePlmn, validateUseCaseRequirements } from './validation';
8
+ export type { ValidationResult } from './validation';
9
+ export { request, FetchError } from './internal/http';
10
+ export type { RequestOptions, HttpResponse } from './internal/http';
11
+ export { getStatusUrl } from './utils';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,uCAAuC,CAAC;AAGtD,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGvF,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC9F,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getStatusUrl = exports.FetchError = exports.request = exports.validateUseCaseRequirements = exports.validatePlmn = exports.validatePhoneNumber = exports.MagicalAuthError = exports.generateRequestId = exports.createLogger = exports.LogLevel = exports.GlideClient = void 0;
18
+ // Re-export all core types and constants (single source of truth)
19
+ __exportStar(require("@glideidentity/glide-be-sdk-node-core"), exports);
20
+ // Main client
21
+ var glide_1 = require("./glide");
22
+ Object.defineProperty(exports, "GlideClient", { enumerable: true, get: function () { return glide_1.GlideClient; } });
23
+ var logger_1 = require("./logger");
24
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
25
+ Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return logger_1.createLogger; } });
26
+ Object.defineProperty(exports, "generateRequestId", { enumerable: true, get: function () { return logger_1.generateRequestId; } });
27
+ // Errors
28
+ var errors_1 = require("./errors");
29
+ Object.defineProperty(exports, "MagicalAuthError", { enumerable: true, get: function () { return errors_1.MagicalAuthError; } });
30
+ // Validation
31
+ var validation_1 = require("./validation");
32
+ Object.defineProperty(exports, "validatePhoneNumber", { enumerable: true, get: function () { return validation_1.validatePhoneNumber; } });
33
+ Object.defineProperty(exports, "validatePlmn", { enumerable: true, get: function () { return validation_1.validatePlmn; } });
34
+ Object.defineProperty(exports, "validateUseCaseRequirements", { enumerable: true, get: function () { return validation_1.validateUseCaseRequirements; } });
35
+ // HTTP utilities - for advanced usage and dev-server
36
+ var http_1 = require("./internal/http");
37
+ Object.defineProperty(exports, "request", { enumerable: true, get: function () { return http_1.request; } });
38
+ Object.defineProperty(exports, "FetchError", { enumerable: true, get: function () { return http_1.FetchError; } });
39
+ // Utility functions
40
+ var utils_1 = require("./utils");
41
+ Object.defineProperty(exports, "getStatusUrl", { enumerable: true, get: function () { return utils_1.getStatusUrl; } });
@@ -0,0 +1,20 @@
1
+ import * as http from 'http';
2
+ export declare class FetchError extends Error {
3
+ response: http.IncomingMessage;
4
+ data: string;
5
+ constructor(response: http.IncomingMessage, data: string);
6
+ }
7
+ export interface RequestOptions {
8
+ method: string;
9
+ headers: Record<string, string>;
10
+ body?: string;
11
+ timeout?: number;
12
+ }
13
+ export interface HttpResponse {
14
+ json: <T = unknown>() => T;
15
+ text: () => string;
16
+ ok: boolean;
17
+ status: number;
18
+ }
19
+ export declare function request(url: string, options: RequestOptions): Promise<HttpResponse>;
20
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/internal/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,qBAAa,UAAW,SAAQ,KAAK;IAC1B,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;gBAER,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,EAAE,MAAM;CAK3D;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,CAAC,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CA+CnF"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.FetchError = void 0;
37
+ exports.request = request;
38
+ const https = __importStar(require("https"));
39
+ const http = __importStar(require("http"));
40
+ const glide_be_sdk_node_core_1 = require("@glideidentity/glide-be-sdk-node-core");
41
+ class FetchError extends Error {
42
+ constructor(response, data) {
43
+ super(`Fetch Error: ${response.statusCode} ${response.statusMessage}`);
44
+ this.response = response;
45
+ this.data = data;
46
+ }
47
+ }
48
+ exports.FetchError = FetchError;
49
+ function request(url, options) {
50
+ return new Promise((resolve, reject) => {
51
+ const urlObj = new URL(url);
52
+ const client = urlObj.protocol === 'https:' ? https : http;
53
+ const req = client.request(url, {
54
+ method: options.method,
55
+ headers: {
56
+ 'User-Agent': `glide-be-sdk-node/${glide_be_sdk_node_core_1.VERSION}`,
57
+ ...options.headers,
58
+ },
59
+ timeout: options.timeout || 30000,
60
+ }, (res) => {
61
+ let data = '';
62
+ res.on('data', (chunk) => {
63
+ data += chunk;
64
+ });
65
+ res.on('end', () => {
66
+ const status = res.statusCode || 500;
67
+ if (status >= 400) {
68
+ reject(new FetchError(res, data));
69
+ return;
70
+ }
71
+ resolve({
72
+ json: () => JSON.parse(data),
73
+ text: () => data,
74
+ ok: status < 400,
75
+ status,
76
+ });
77
+ });
78
+ });
79
+ req.on('error', reject);
80
+ req.on('timeout', () => {
81
+ req.destroy();
82
+ reject(new Error('Request timeout'));
83
+ });
84
+ if (options.body) {
85
+ req.write(options.body);
86
+ }
87
+ req.end();
88
+ });
89
+ }
@@ -0,0 +1,53 @@
1
+ import type { Logger } from '../logger';
2
+ /**
3
+ * OAuth2 Client Credentials authentication manager.
4
+ * Manages token fetching and caching with automatic refresh before expiry.
5
+ */
6
+ export declare class OAuthManager {
7
+ private clientId;
8
+ private clientSecret;
9
+ private tokenUrl;
10
+ private refreshBuffer;
11
+ private logger;
12
+ private cachedToken;
13
+ /** Pending token fetch promise for request deduplication. */
14
+ private pendingTokenPromise;
15
+ constructor(clientId: string, clientSecret: string, baseUrl: string, logger: Logger, refreshBuffer?: number);
16
+ /**
17
+ * Gets a valid access token, fetching a new one if necessary.
18
+ * Implements lazy refresh - tokens are refreshed before they expire.
19
+ * Uses pending promise deduplication to prevent multiple concurrent token fetches.
20
+ */
21
+ getAccessToken(): Promise<string>;
22
+ /**
23
+ * Fetches and caches a new token. Separated for promise deduplication.
24
+ */
25
+ private fetchAndCacheToken;
26
+ /**
27
+ * Checks if the cached token is still valid (not expired or about to expire).
28
+ */
29
+ private isTokenValid;
30
+ /**
31
+ * Fetches a new access token from the OAuth2 token endpoint.
32
+ * Uses HTTP Basic authentication with base64-encoded credentials.
33
+ * Most OAuth2 servers expect raw client credentials to be base64-encoded directly
34
+ * in the Authorization header without additional URL-encoding.
35
+ *
36
+ */
37
+ private fetchToken;
38
+ /**
39
+ * Caches the token with its expiration time.
40
+ */
41
+ private cacheToken;
42
+ /**
43
+ * Clears the cached token. Useful for forcing a token refresh.
44
+ */
45
+ clearCache(): void;
46
+ }
47
+ export declare class OAuthError extends Error {
48
+ readonly statusCode: number;
49
+ readonly statusMessage: string;
50
+ constructor(statusCode: number, statusMessage: string);
51
+ }
52
+ export { OAuthManager as OAuthClient };
53
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/internal/oauth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAKxC;;;GAGG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAA4B;IAC/C,6DAA6D;IAC7D,OAAO,CAAC,mBAAmB,CAAgC;gBAGvD,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,MAA6C;IAShE;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAyBvC;;OAEG;YACW,kBAAkB;IAMhC;;OAEG;IACH,OAAO,CAAC,YAAY;IAgBpB;;;;;;OAMG;YACW,UAAU;IAqCxB;;OAEG;IACH,OAAO,CAAC,UAAU;IAYlB;;OAEG;IACH,UAAU,IAAI,IAAI;CAIrB;AAED,qBAAa,UAAW,SAAQ,KAAK;IACjC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,aAAa,EAAE,MAAM,CAAC;gBAE1B,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAMxD;AAGD,OAAO,EAAE,YAAY,IAAI,WAAW,EAAE,CAAC"}