@scalekit-sdk/node 2.4.0 → 2.5.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/lib/actions.d.ts +169 -0
- package/lib/actions.js +286 -0
- package/lib/actions.js.map +1 -0
- package/lib/connected-accounts.d.ts +149 -0
- package/lib/connected-accounts.js +213 -0
- package/lib/connected-accounts.js.map +1 -0
- package/lib/core.d.ts +5 -3
- package/lib/core.js +35 -13
- package/lib/core.js.map +1 -1
- package/lib/m2mclient.d.ts +122 -0
- package/lib/m2mclient.js +172 -0
- package/lib/m2mclient.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js +2 -1
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/clients/clients_pb.d.ts +2597 -0
- package/lib/pkg/grpc/scalekit/v1/clients/clients_pb.js +546 -0
- package/lib/pkg/grpc/scalekit/v1/clients/clients_pb.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.d.ts +798 -0
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js +233 -0
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +78 -0
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +17 -2
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.d.ts +70 -0
- package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js +18 -2
- package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.d.ts +13 -0
- package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +8 -0
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +1 -1
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.d.ts +504 -0
- package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js +118 -0
- package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +1 -1
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
- package/lib/role.d.ts +47 -1
- package/lib/role.js +65 -0
- package/lib/role.js.map +1 -1
- package/lib/scalekit.d.ts +8 -0
- package/lib/scalekit.js +8 -0
- package/lib/scalekit.js.map +1 -1
- package/lib/token.d.ts +34 -2
- package/lib/token.js +30 -0
- package/lib/token.js.map +1 -1
- package/lib/tools.d.ts +96 -0
- package/lib/tools.js +108 -0
- package/lib/tools.js.map +1 -0
- package/lib/user.d.ts +54 -1
- package/lib/user.js +85 -0
- package/lib/user.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const connected_accounts_pb_1 = require("./pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb");
|
|
15
|
+
/**
|
|
16
|
+
* Client for managing connected accounts for third-party integrations.
|
|
17
|
+
*
|
|
18
|
+
* This mirrors the Python SDK `ConnectedAccountsClient` and exposes a typed,
|
|
19
|
+
* ergonomic API around the `ConnectedAccountService` to:
|
|
20
|
+
* - list connected accounts
|
|
21
|
+
* - create/update/delete connected accounts
|
|
22
|
+
* - generate magic links for authorization
|
|
23
|
+
* - fetch full authentication details for a connected account
|
|
24
|
+
*/
|
|
25
|
+
class ConnectedAccountsClient {
|
|
26
|
+
constructor(grpcConnect, coreClient) {
|
|
27
|
+
this.grpcConnect = grpcConnect;
|
|
28
|
+
this.coreClient = coreClient;
|
|
29
|
+
this.client = this.grpcConnect.createClient(connected_accounts_pb_1.ConnectedAccountService);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lists connected accounts with optional filters and pagination.
|
|
33
|
+
*
|
|
34
|
+
* @param options Optional filtering and pagination parameters
|
|
35
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
36
|
+
*/
|
|
37
|
+
listConnectedAccounts(options) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
return this.coreClient.connectExec(this.client.listConnectedAccounts, (0, protobuf_1.create)(connected_accounts_pb_1.ListConnectedAccountsRequestSchema, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.organizationId) && {
|
|
41
|
+
organizationId: options.organizationId,
|
|
42
|
+
})), ((options === null || options === void 0 ? void 0 : options.userId) && { userId: options.userId })), (((_a = options === null || options === void 0 ? void 0 : options.connector) === null || _a === void 0 ? void 0 : _a.trim()) && {
|
|
43
|
+
connector: options.connector.trim(),
|
|
44
|
+
})), (((_b = options === null || options === void 0 ? void 0 : options.identifier) === null || _b === void 0 ? void 0 : _b.trim()) && {
|
|
45
|
+
identifier: options.identifier.trim(),
|
|
46
|
+
})), (((_c = options === null || options === void 0 ? void 0 : options.provider) === null || _c === void 0 ? void 0 : _c.trim()) && { provider: options.provider.trim() })), ((options === null || options === void 0 ? void 0 : options.pageSize) !== undefined && { pageSize: options.pageSize })), ((options === null || options === void 0 ? void 0 : options.pageToken) && { pageToken: options.pageToken })), ((options === null || options === void 0 ? void 0 : options.query) && { query: options.query }))));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new connected account.
|
|
51
|
+
*
|
|
52
|
+
* @param params Connected account creation parameters
|
|
53
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
54
|
+
*/
|
|
55
|
+
createConnectedAccount(params) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const { connector, identifier, connectedAccount, organizationId, userId } = params;
|
|
58
|
+
return this.coreClient.connectExec(this.client.createConnectedAccount, (0, protobuf_1.create)(connected_accounts_pb_1.CreateConnectedAccountRequestSchema, Object.assign(Object.assign({ connector,
|
|
59
|
+
identifier,
|
|
60
|
+
connectedAccount }, (organizationId && { organizationId })), (userId && { userId }))));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets an existing connected account by connector and identifier, or creates one if none exists.
|
|
65
|
+
* Mirrors the Python SDK `get_or_create_connected_account`. When creating, the backend may require
|
|
66
|
+
* valid authorization details; if omitted, a minimal payload is sent and the server may return
|
|
67
|
+
* a validation error.
|
|
68
|
+
*
|
|
69
|
+
* @param params Get-or-create parameters
|
|
70
|
+
* @param params.connector Connector identifier (required)
|
|
71
|
+
* @param params.identifier Connected account identifier (required)
|
|
72
|
+
* @param params.authorizationDetails Optional auth details for the create path (OAuth token or static auth)
|
|
73
|
+
* @param params.organizationId Optional organization ID
|
|
74
|
+
* @param params.userId Optional user ID
|
|
75
|
+
* @param params.apiConfig Optional API config for the create path
|
|
76
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
77
|
+
* @throws {ScalekitException} If connector or identifier is missing.
|
|
78
|
+
*/
|
|
79
|
+
getOrCreateConnectedAccount(params) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const { connector: rawConnector, identifier: rawIdentifier, authorizationDetails, organizationId, userId, apiConfig, } = params;
|
|
82
|
+
const connector = rawConnector === null || rawConnector === void 0 ? void 0 : rawConnector.trim();
|
|
83
|
+
const identifier = rawIdentifier === null || rawIdentifier === void 0 ? void 0 : rawIdentifier.trim();
|
|
84
|
+
if (!connector) {
|
|
85
|
+
throw new Error('connector is required');
|
|
86
|
+
}
|
|
87
|
+
if (!identifier) {
|
|
88
|
+
throw new Error('identifier is required');
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const getResponse = yield this.getConnectedAccountByIdentifier({
|
|
92
|
+
connector,
|
|
93
|
+
identifier,
|
|
94
|
+
organizationId,
|
|
95
|
+
userId,
|
|
96
|
+
});
|
|
97
|
+
return (0, protobuf_1.create)(connected_accounts_pb_1.CreateConnectedAccountResponseSchema, {
|
|
98
|
+
connectedAccount: getResponse.connectedAccount,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (!(err instanceof errors_1.ScalekitNotFoundException)) {
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const resolvedAuthDetails = authorizationDetails
|
|
107
|
+
? (0, protobuf_1.create)(connected_accounts_pb_1.AuthorizationDetailsSchema, authorizationDetails)
|
|
108
|
+
: (0, protobuf_1.create)(connected_accounts_pb_1.AuthorizationDetailsSchema, {
|
|
109
|
+
details: { case: 'oauthToken', value: (0, protobuf_1.create)(connected_accounts_pb_1.OauthTokenSchema, {}) },
|
|
110
|
+
});
|
|
111
|
+
const connectedAccountPayload = (0, protobuf_1.create)(connected_accounts_pb_1.CreateConnectedAccountSchema, Object.assign({ authorizationDetails: resolvedAuthDetails }, (apiConfig != null && {
|
|
112
|
+
apiConfig: apiConfig,
|
|
113
|
+
})));
|
|
114
|
+
return this.createConnectedAccount({
|
|
115
|
+
connector,
|
|
116
|
+
identifier,
|
|
117
|
+
connectedAccount: connectedAccountPayload,
|
|
118
|
+
organizationId,
|
|
119
|
+
userId,
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Updates an existing connected account.
|
|
125
|
+
*
|
|
126
|
+
* You can target the account either by `connectedAccountId` alone, or by the
|
|
127
|
+
* combination of `connector` and `identifier`.
|
|
128
|
+
*
|
|
129
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
130
|
+
* @throws {ScalekitException} If required parameters are missing.
|
|
131
|
+
*/
|
|
132
|
+
updateConnectedAccount(params) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const { connector, identifier, connectedAccount, organizationId, userId, connectedAccountId, } = params;
|
|
135
|
+
if (!connectedAccountId && !((connector === null || connector === void 0 ? void 0 : connector.trim()) && (identifier === null || identifier === void 0 ? void 0 : identifier.trim()))) {
|
|
136
|
+
throw new Error('either connectedAccountId or connector + identifier is required');
|
|
137
|
+
}
|
|
138
|
+
return this.coreClient.connectExec(this.client.updateConnectedAccount, (0, protobuf_1.create)(connected_accounts_pb_1.UpdateConnectedAccountRequestSchema, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((connector === null || connector === void 0 ? void 0 : connector.trim()) && { connector: connector.trim() })), ((identifier === null || identifier === void 0 ? void 0 : identifier.trim()) && { identifier: identifier.trim() })), { connectedAccount }), (organizationId && { organizationId })), (userId && { userId })), (connectedAccountId && { id: connectedAccountId }))));
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Deletes a connected account and revokes its credentials.
|
|
143
|
+
*
|
|
144
|
+
* You can target the account either by `connectedAccountId` alone, or by the
|
|
145
|
+
* combination of `connector` and `identifier`.
|
|
146
|
+
*
|
|
147
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
148
|
+
* @throws {ScalekitException} If required parameters are missing.
|
|
149
|
+
*/
|
|
150
|
+
deleteConnectedAccount(params) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const { connector, identifier, organizationId, userId, connectedAccountId, } = params;
|
|
153
|
+
if (!connectedAccountId && !((connector === null || connector === void 0 ? void 0 : connector.trim()) && (identifier === null || identifier === void 0 ? void 0 : identifier.trim()))) {
|
|
154
|
+
throw new Error('either connectedAccountId or connector + identifier is required');
|
|
155
|
+
}
|
|
156
|
+
return this.coreClient.connectExec(this.client.deleteConnectedAccount, (0, protobuf_1.create)(connected_accounts_pb_1.DeleteConnectedAccountRequestSchema, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((connector === null || connector === void 0 ? void 0 : connector.trim()) && { connector: connector.trim() })), ((identifier === null || identifier === void 0 ? void 0 : identifier.trim()) && { identifier: identifier.trim() })), (organizationId && { organizationId })), (userId && { userId })), (connectedAccountId && { id: connectedAccountId }))));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Generates a time-limited magic link for connecting or re-authorizing a third-party account.
|
|
161
|
+
*
|
|
162
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
163
|
+
*/
|
|
164
|
+
getMagicLinkForConnectedAccount(params) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const { connector, identifier, organizationId, userId, connectedAccountId, state, userVerifyUrl, } = params;
|
|
167
|
+
return this.coreClient.connectExec(this.client.getMagicLinkForConnectedAccount, (0, protobuf_1.create)(connected_accounts_pb_1.GetMagicLinkForConnectedAccountRequestSchema, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (connector && { connector })), (identifier && { identifier })), (organizationId && { organizationId })), (userId && { userId })), (connectedAccountId && { id: connectedAccountId })), (state && { state })), (userVerifyUrl && { userVerifyUrl }))));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Verifies the connected account user after OAuth callback.
|
|
172
|
+
*
|
|
173
|
+
* Called by the B2B app server with the `auth_request_id` from the user verify
|
|
174
|
+
* redirect URL and the current user's identifier. Validates that the asserted
|
|
175
|
+
* identifier matches the one stored on the auth request and activates the account.
|
|
176
|
+
*
|
|
177
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
178
|
+
*/
|
|
179
|
+
verifyConnectedAccountUser(params) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
const authRequestId = (_a = params.authRequestId) === null || _a === void 0 ? void 0 : _a.trim();
|
|
183
|
+
const identifier = (_b = params.identifier) === null || _b === void 0 ? void 0 : _b.trim();
|
|
184
|
+
if (!authRequestId) {
|
|
185
|
+
throw new Error('authRequestId is required');
|
|
186
|
+
}
|
|
187
|
+
if (!identifier) {
|
|
188
|
+
throw new Error('identifier is required');
|
|
189
|
+
}
|
|
190
|
+
return this.coreClient.connectExec(this.client.verifyConnectedAccountUser, (0, protobuf_1.create)(connected_accounts_pb_1.VerifyConnectedAccountUserRequestSchema, {
|
|
191
|
+
authRequestId,
|
|
192
|
+
identifier,
|
|
193
|
+
}));
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves complete authentication details for a connected account.
|
|
198
|
+
*
|
|
199
|
+
* This method returns sensitive credential information, so ensure you protect access
|
|
200
|
+
* to this in your application.
|
|
201
|
+
*
|
|
202
|
+
* @throws {ScalekitServerException} If a network or server error occurs.
|
|
203
|
+
* @throws {ScalekitNotFoundException} If no matching connected account is found.
|
|
204
|
+
*/
|
|
205
|
+
getConnectedAccountByIdentifier(params) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
const { connector, identifier, organizationId, userId, connectedAccountId, } = params;
|
|
208
|
+
return this.coreClient.connectExec(this.client.getConnectedAccountAuth, (0, protobuf_1.create)(connected_accounts_pb_1.GetConnectedAccountByIdentifierRequestSchema, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (connector && { connector })), (identifier && { identifier })), (organizationId && { organizationId })), (userId && { userId })), (connectedAccountId && { id: connectedAccountId }))));
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.default = ConnectedAccountsClient;
|
|
213
|
+
//# sourceMappingURL=connected-accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connected-accounts.js","sourceRoot":"","sources":["../src/connected-accounts.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iDAAmE;AAInE,qCAAwE;AACxE,2GAuByE;AAEzE;;;;;;;;;GASG;AACH,MAAqB,uBAAuB;IAG1C,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,+CAAuB,CAAC,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACG,qBAAqB,CAAC,OAS3B;;;YACC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,qBAAqB,EACjC,IAAA,iBAAM,EAAC,0DAAkC,sHACpC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,KAAI;gBAC7B,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC,CAAC,GACC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,GAC/C,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,IAAI,EAAE,KAAI;g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nC,IAAA,iBAAM,EAAC,oEAA4C,4EAC9C,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC,GAC5B,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,CAAC,GAC9B,CAAC,cAAc,IAAI,EAAE,cAAc,EAAE,CAAC,GACtC,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC,GACtB,CAAC,kBAAkB,IAAI,EAAE,EAAE,EAAE,kBAAkB,EAAE,CAAC,EACrD,CACH,CAAC;QACJ,CAAC;KAAA;CACF;AA5VD,0CA4VC"}
|
package/lib/core.d.ts
CHANGED
|
@@ -38,12 +38,14 @@ export default class CoreClient {
|
|
|
38
38
|
* @returns {Promise<void>} Returns nothing
|
|
39
39
|
*/
|
|
40
40
|
getJwks(): Promise<void>;
|
|
41
|
+
private sleep;
|
|
41
42
|
/**
|
|
42
|
-
* Execute a function with error handling and retry logic
|
|
43
|
+
* Execute a function with error handling and retry logic.
|
|
44
|
+
*
|
|
43
45
|
* @param fn Function to execute
|
|
44
46
|
* @param data Data to pass to the function
|
|
45
|
-
* @param retryLeft Number of retries left
|
|
46
47
|
* @returns {Promise<TResponse>} Returns the response
|
|
47
48
|
*/
|
|
48
|
-
connectExec<TRequest, TResponse>(fn: (request: TRequest) => Promise<TResponse>, data: TRequest
|
|
49
|
+
connectExec<TRequest, TResponse>(fn: (request: TRequest) => Promise<TResponse>, data: TRequest): Promise<TResponse>;
|
|
50
|
+
private _connectExec;
|
|
49
51
|
}
|
package/lib/core.js
CHANGED
|
@@ -69,7 +69,8 @@ class CoreClient {
|
|
|
69
69
|
this.accessToken = null;
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
71
71
|
this.sdkVersion = `Scalekit-Node/${require('../package.json').version}`;
|
|
72
|
-
|
|
72
|
+
// YYYYMMDD
|
|
73
|
+
this.apiVersion = '20260402';
|
|
73
74
|
this.userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os_1.default.arch()})`;
|
|
74
75
|
this.axios = axios_1.default.create({ baseURL: envUrl });
|
|
75
76
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -122,27 +123,43 @@ class CoreClient {
|
|
|
122
123
|
this.keys = keys;
|
|
123
124
|
});
|
|
124
125
|
}
|
|
126
|
+
sleep(ms) {
|
|
127
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
128
|
+
}
|
|
125
129
|
/**
|
|
126
|
-
* Execute a function with error handling and retry logic
|
|
130
|
+
* Execute a function with error handling and retry logic.
|
|
131
|
+
*
|
|
127
132
|
* @param fn Function to execute
|
|
128
133
|
* @param data Data to pass to the function
|
|
129
|
-
* @param retryLeft Number of retries left
|
|
130
134
|
* @returns {Promise<TResponse>} Returns the response
|
|
131
135
|
*/
|
|
132
|
-
connectExec(
|
|
133
|
-
return __awaiter(this,
|
|
136
|
+
connectExec(fn, data) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
return this._connectExec(fn, data, 3, 0);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
_connectExec(fn, data, retryLeft, attempt) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
143
|
try {
|
|
135
|
-
|
|
136
|
-
return res;
|
|
144
|
+
return yield fn(data);
|
|
137
145
|
}
|
|
138
146
|
catch (error) {
|
|
139
147
|
// Handle gRPC Connect errors
|
|
140
148
|
if (error instanceof connect_1.ConnectError) {
|
|
141
149
|
if (retryLeft > 0) {
|
|
142
|
-
|
|
143
|
-
if (serverException.httpStatus === 401) {
|
|
150
|
+
if (error.code === connect_1.Code.Unauthenticated) {
|
|
144
151
|
yield this.authenticateClient();
|
|
145
|
-
return this.
|
|
152
|
+
return this._connectExec(fn, data, retryLeft - 1, attempt + 1);
|
|
153
|
+
}
|
|
154
|
+
// The Connect transport maps HTTP 429 to Code.Unavailable with a 429 body,
|
|
155
|
+
// and gRPC-native rate limits come as Code.ResourceExhausted.
|
|
156
|
+
const is429 = error.code === connect_1.Code.ResourceExhausted ||
|
|
157
|
+
(error.code === connect_1.Code.Unavailable && error.message.includes('429'));
|
|
158
|
+
if (is429) {
|
|
159
|
+
const baseBackoff = Math.min(1000 * Math.pow(2, attempt), 30000);
|
|
160
|
+
const backoffMs = baseBackoff * (0.5 + Math.random() * 0.5);
|
|
161
|
+
yield this.sleep(backoffMs);
|
|
162
|
+
return this._connectExec(fn, data, retryLeft - 1, attempt + 1);
|
|
146
163
|
}
|
|
147
164
|
}
|
|
148
165
|
throw base_exception_1.ScalekitServerException.promote(error);
|
|
@@ -151,10 +168,15 @@ class CoreClient {
|
|
|
151
168
|
if (error instanceof axios_1.AxiosError) {
|
|
152
169
|
if (error.response) {
|
|
153
170
|
if (retryLeft > 0) {
|
|
154
|
-
|
|
155
|
-
if (serverException.httpStatus === 401) {
|
|
171
|
+
if (error.response.status === 401) {
|
|
156
172
|
yield this.authenticateClient();
|
|
157
|
-
return this.
|
|
173
|
+
return this._connectExec(fn, data, retryLeft - 1, attempt + 1);
|
|
174
|
+
}
|
|
175
|
+
if (error.response.status === 429) {
|
|
176
|
+
const baseBackoff = Math.min(1000 * Math.pow(2, attempt), 30000);
|
|
177
|
+
const backoffMs = baseBackoff * (0.5 + Math.random() * 0.5);
|
|
178
|
+
yield this.sleep(backoffMs);
|
|
179
|
+
return this._connectExec(fn, data, retryLeft - 1, attempt + 1);
|
|
158
180
|
}
|
|
159
181
|
}
|
|
160
182
|
throw base_exception_1.ScalekitServerException.promote(error.response);
|
package/lib/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAyD;AACzD,+CAMe;AAWf,4CAAoB;AACpB,4CAA6B;AAC7B,+CAA6C;AAE7C,4DAGiC;AAEpB,QAAA,OAAO,GAAG;IACrB,YAAY,EAAE,YAAY;IAC1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AC;gCAC5D,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gCAC5B,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;4BACjE,CAAC;wBACH,CAAC;wBACD,MAAM,wCAAuB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBACxD,CAAC;yBAAM,CAAC;wBACN,MAAM,IAAI,kCAAiB,CAAC,KAAK,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC;gBACD,8CAA8C;gBAC9C,IAAI,KAAK,YAAY,kCAAiB,EAAE,CAAC;oBACvC,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,wBAAwB;gBACxB,MAAM,IAAI,kCAAiB,CAAC,KAAK,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;KAAA;CACF;AAlJD,6BAkJC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { MessageShape } from '@bufbuild/protobuf';
|
|
2
|
+
import { EmptySchema } from '@bufbuild/protobuf/wkt';
|
|
3
|
+
import GrpcConnect from './connect';
|
|
4
|
+
import CoreClient from './core';
|
|
5
|
+
import { OrganizationClient, CreateOrganizationClientResponse, GetOrganizationClientResponse, UpdateOrganizationClientResponse, CreateOrganizationClientSecretResponse, ListOrganizationClientsResponse } from './pkg/grpc/scalekit/v1/clients/clients_pb';
|
|
6
|
+
export interface CreateOrganizationClientOptions {
|
|
7
|
+
/** Human-readable name for the client */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Optional description */
|
|
10
|
+
description?: string;
|
|
11
|
+
/** Custom claims to embed in access tokens (key-value pairs) */
|
|
12
|
+
customClaims?: {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
};
|
|
15
|
+
/** Audience values for access tokens */
|
|
16
|
+
audience?: string[];
|
|
17
|
+
/** Scopes to grant */
|
|
18
|
+
scopes?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface UpdateOrganizationClientOptions {
|
|
21
|
+
/** Updated name */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** Updated description */
|
|
24
|
+
description?: string;
|
|
25
|
+
/** Custom claims to set (replaces existing) */
|
|
26
|
+
customClaims?: {
|
|
27
|
+
[key: string]: string;
|
|
28
|
+
};
|
|
29
|
+
/** Updated audience values */
|
|
30
|
+
audience?: string[];
|
|
31
|
+
/** Updated scopes */
|
|
32
|
+
scopes?: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface ListOrganizationClientsOptions {
|
|
35
|
+
/** Page size (between 10 and 100) */
|
|
36
|
+
pageSize?: number;
|
|
37
|
+
/** Pagination cursor for next page */
|
|
38
|
+
pageToken?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Client for managing M2M (machine-to-machine) API clients per organization.
|
|
42
|
+
*
|
|
43
|
+
* Each organization client represents an automated system credential scoped
|
|
44
|
+
* to one organization, using the client_credentials OAuth flow.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
|
|
48
|
+
* const m2m = scalekitClient.m2m;
|
|
49
|
+
*
|
|
50
|
+
* @see {@link https://docs.scalekit.com/m2m/overview | M2M Documentation}
|
|
51
|
+
*/
|
|
52
|
+
export default class M2MClient {
|
|
53
|
+
private readonly grpcConnect;
|
|
54
|
+
private readonly coreClient;
|
|
55
|
+
private client;
|
|
56
|
+
constructor(grpcConnect: GrpcConnect, coreClient: CoreClient);
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new M2M API client for an organization.
|
|
59
|
+
*
|
|
60
|
+
* Returns a `clientId` and a plain `secret` (only available at creation time).
|
|
61
|
+
*
|
|
62
|
+
* @param organizationId - The organization to create the client for
|
|
63
|
+
* @param options - Optional client properties (name, description, customClaims, audience, scopes)
|
|
64
|
+
* @returns CreateOrganizationClientResponse with clientId, secret, and client metadata
|
|
65
|
+
*/
|
|
66
|
+
createOrganizationClient(organizationId: string, options?: CreateOrganizationClientOptions): Promise<CreateOrganizationClientResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves details of a specific M2M client for an organization.
|
|
69
|
+
*
|
|
70
|
+
* @param organizationId - The organization ID
|
|
71
|
+
* @param clientId - The client ID (format: skc_xxxxx)
|
|
72
|
+
* @returns GetOrganizationClientResponse with client metadata and active secrets (values hidden)
|
|
73
|
+
*/
|
|
74
|
+
getOrganizationClient(organizationId: string, clientId: string): Promise<GetOrganizationClientResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Updates the configuration of an existing M2M client.
|
|
77
|
+
*
|
|
78
|
+
* @param organizationId - The organization ID
|
|
79
|
+
* @param clientId - The client ID to update
|
|
80
|
+
* @param options - Fields to update (name, description, customClaims, audience, scopes)
|
|
81
|
+
* @returns UpdateOrganizationClientResponse with updated client metadata
|
|
82
|
+
*/
|
|
83
|
+
updateOrganizationClient(organizationId: string, clientId: string, options?: UpdateOrganizationClientOptions): Promise<UpdateOrganizationClientResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Permanently deletes an M2M client from an organization.
|
|
86
|
+
*
|
|
87
|
+
* This operation cannot be undone. All associated secrets are invalidated.
|
|
88
|
+
*
|
|
89
|
+
* @param organizationId - The organization ID
|
|
90
|
+
* @param clientId - The client ID to delete
|
|
91
|
+
* @returns Empty response on success
|
|
92
|
+
*/
|
|
93
|
+
deleteOrganizationClient(organizationId: string, clientId: string): Promise<MessageShape<typeof EmptySchema>>;
|
|
94
|
+
/**
|
|
95
|
+
* Adds a new secret to an M2M client.
|
|
96
|
+
*
|
|
97
|
+
* The plain secret value is returned only at creation time and cannot be retrieved again.
|
|
98
|
+
*
|
|
99
|
+
* @param organizationId - The organization ID
|
|
100
|
+
* @param clientId - The client ID to add a secret to
|
|
101
|
+
* @returns CreateOrganizationClientSecretResponse with secretId and plain secret
|
|
102
|
+
*/
|
|
103
|
+
addOrganizationClientSecret(organizationId: string, clientId: string): Promise<CreateOrganizationClientSecretResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Permanently removes a secret from an M2M client.
|
|
106
|
+
*
|
|
107
|
+
* @param organizationId - The organization ID
|
|
108
|
+
* @param clientId - The client ID
|
|
109
|
+
* @param secretId - The secret ID to remove
|
|
110
|
+
* @returns Empty response on success
|
|
111
|
+
*/
|
|
112
|
+
removeOrganizationClientSecret(organizationId: string, clientId: string, secretId: string): Promise<MessageShape<typeof EmptySchema>>;
|
|
113
|
+
/**
|
|
114
|
+
* Lists all M2M clients for an organization with pagination.
|
|
115
|
+
*
|
|
116
|
+
* @param organizationId - The organization ID
|
|
117
|
+
* @param options - Optional pagination options (pageSize 10–100, pageToken)
|
|
118
|
+
* @returns ListOrganizationClientsResponse with clients array and pagination cursors
|
|
119
|
+
*/
|
|
120
|
+
listOrganizationClients(organizationId: string, options?: ListOrganizationClientsOptions): Promise<ListOrganizationClientsResponse>;
|
|
121
|
+
}
|
|
122
|
+
export { OrganizationClient, CreateOrganizationClientResponse, GetOrganizationClientResponse, UpdateOrganizationClientResponse, CreateOrganizationClientSecretResponse, ListOrganizationClientsResponse, };
|
package/lib/m2mclient.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
13
|
+
const clients_pb_1 = require("./pkg/grpc/scalekit/v1/clients/clients_pb");
|
|
14
|
+
function toCustomClaims(claims) {
|
|
15
|
+
return Object.entries(claims).map(([key, value]) => (0, protobuf_1.create)(clients_pb_1.CustomClaimSchema, { key, value }));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Client for managing M2M (machine-to-machine) API clients per organization.
|
|
19
|
+
*
|
|
20
|
+
* Each organization client represents an automated system credential scoped
|
|
21
|
+
* to one organization, using the client_credentials OAuth flow.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
|
|
25
|
+
* const m2m = scalekitClient.m2m;
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://docs.scalekit.com/m2m/overview | M2M Documentation}
|
|
28
|
+
*/
|
|
29
|
+
class M2MClient {
|
|
30
|
+
constructor(grpcConnect, coreClient) {
|
|
31
|
+
this.grpcConnect = grpcConnect;
|
|
32
|
+
this.coreClient = coreClient;
|
|
33
|
+
this.client = this.grpcConnect.createClient(clients_pb_1.ClientService);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new M2M API client for an organization.
|
|
37
|
+
*
|
|
38
|
+
* Returns a `clientId` and a plain `secret` (only available at creation time).
|
|
39
|
+
*
|
|
40
|
+
* @param organizationId - The organization to create the client for
|
|
41
|
+
* @param options - Optional client properties (name, description, customClaims, audience, scopes)
|
|
42
|
+
* @returns CreateOrganizationClientResponse with clientId, secret, and client metadata
|
|
43
|
+
*/
|
|
44
|
+
createOrganizationClient(organizationId, options) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (!organizationId)
|
|
47
|
+
throw new Error('organizationId is required');
|
|
48
|
+
return this.coreClient.connectExec(this.client.createOrganizationClient, {
|
|
49
|
+
organizationId,
|
|
50
|
+
client: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.name) && { name: options.name })), ((options === null || options === void 0 ? void 0 : options.description) && { description: options.description })), ((options === null || options === void 0 ? void 0 : options.customClaims) && {
|
|
51
|
+
customClaims: toCustomClaims(options.customClaims),
|
|
52
|
+
})), ((options === null || options === void 0 ? void 0 : options.audience) && { audience: options.audience })), ((options === null || options === void 0 ? void 0 : options.scopes) && { scopes: options.scopes })),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves details of a specific M2M client for an organization.
|
|
58
|
+
*
|
|
59
|
+
* @param organizationId - The organization ID
|
|
60
|
+
* @param clientId - The client ID (format: skc_xxxxx)
|
|
61
|
+
* @returns GetOrganizationClientResponse with client metadata and active secrets (values hidden)
|
|
62
|
+
*/
|
|
63
|
+
getOrganizationClient(organizationId, clientId) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (!organizationId)
|
|
66
|
+
throw new Error('organizationId is required');
|
|
67
|
+
if (!clientId)
|
|
68
|
+
throw new Error('clientId is required');
|
|
69
|
+
return this.coreClient.connectExec(this.client.getOrganizationClient, {
|
|
70
|
+
organizationId,
|
|
71
|
+
clientId,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Updates the configuration of an existing M2M client.
|
|
77
|
+
*
|
|
78
|
+
* @param organizationId - The organization ID
|
|
79
|
+
* @param clientId - The client ID to update
|
|
80
|
+
* @param options - Fields to update (name, description, customClaims, audience, scopes)
|
|
81
|
+
* @returns UpdateOrganizationClientResponse with updated client metadata
|
|
82
|
+
*/
|
|
83
|
+
updateOrganizationClient(organizationId, clientId, options) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (!organizationId)
|
|
86
|
+
throw new Error('organizationId is required');
|
|
87
|
+
if (!clientId)
|
|
88
|
+
throw new Error('clientId is required');
|
|
89
|
+
return this.coreClient.connectExec(this.client.updateOrganizationClient, {
|
|
90
|
+
organizationId,
|
|
91
|
+
clientId,
|
|
92
|
+
client: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.name) && { name: options.name })), ((options === null || options === void 0 ? void 0 : options.description) && { description: options.description })), ((options === null || options === void 0 ? void 0 : options.customClaims) && {
|
|
93
|
+
customClaims: toCustomClaims(options.customClaims),
|
|
94
|
+
})), ((options === null || options === void 0 ? void 0 : options.audience) && { audience: options.audience })), ((options === null || options === void 0 ? void 0 : options.scopes) && { scopes: options.scopes })),
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Permanently deletes an M2M client from an organization.
|
|
100
|
+
*
|
|
101
|
+
* This operation cannot be undone. All associated secrets are invalidated.
|
|
102
|
+
*
|
|
103
|
+
* @param organizationId - The organization ID
|
|
104
|
+
* @param clientId - The client ID to delete
|
|
105
|
+
* @returns Empty response on success
|
|
106
|
+
*/
|
|
107
|
+
deleteOrganizationClient(organizationId, clientId) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
if (!organizationId)
|
|
110
|
+
throw new Error('organizationId is required');
|
|
111
|
+
if (!clientId)
|
|
112
|
+
throw new Error('clientId is required');
|
|
113
|
+
return this.coreClient.connectExec(this.client.deleteOrganizationClient, {
|
|
114
|
+
organizationId,
|
|
115
|
+
clientId,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds a new secret to an M2M client.
|
|
121
|
+
*
|
|
122
|
+
* The plain secret value is returned only at creation time and cannot be retrieved again.
|
|
123
|
+
*
|
|
124
|
+
* @param organizationId - The organization ID
|
|
125
|
+
* @param clientId - The client ID to add a secret to
|
|
126
|
+
* @returns CreateOrganizationClientSecretResponse with secretId and plain secret
|
|
127
|
+
*/
|
|
128
|
+
addOrganizationClientSecret(organizationId, clientId) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
if (!organizationId)
|
|
131
|
+
throw new Error('organizationId is required');
|
|
132
|
+
if (!clientId)
|
|
133
|
+
throw new Error('clientId is required');
|
|
134
|
+
return this.coreClient.connectExec(this.client.createOrganizationClientSecret, { organizationId, clientId });
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Permanently removes a secret from an M2M client.
|
|
139
|
+
*
|
|
140
|
+
* @param organizationId - The organization ID
|
|
141
|
+
* @param clientId - The client ID
|
|
142
|
+
* @param secretId - The secret ID to remove
|
|
143
|
+
* @returns Empty response on success
|
|
144
|
+
*/
|
|
145
|
+
removeOrganizationClientSecret(organizationId, clientId, secretId) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
if (!organizationId)
|
|
148
|
+
throw new Error('organizationId is required');
|
|
149
|
+
if (!clientId)
|
|
150
|
+
throw new Error('clientId is required');
|
|
151
|
+
if (!secretId)
|
|
152
|
+
throw new Error('secretId is required');
|
|
153
|
+
return this.coreClient.connectExec(this.client.deleteOrganizationClientSecret, { organizationId, clientId, secretId });
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Lists all M2M clients for an organization with pagination.
|
|
158
|
+
*
|
|
159
|
+
* @param organizationId - The organization ID
|
|
160
|
+
* @param options - Optional pagination options (pageSize 10–100, pageToken)
|
|
161
|
+
* @returns ListOrganizationClientsResponse with clients array and pagination cursors
|
|
162
|
+
*/
|
|
163
|
+
listOrganizationClients(organizationId, options) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
if (!organizationId)
|
|
166
|
+
throw new Error('organizationId is required');
|
|
167
|
+
return this.coreClient.connectExec(this.client.listOrganizationClients, Object.assign(Object.assign({ organizationId }, ((options === null || options === void 0 ? void 0 : options.pageSize) !== undefined && { pageSize: options.pageSize })), ((options === null || options === void 0 ? void 0 : options.pageToken) && { pageToken: options.pageToken })));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.default = M2MClient;
|
|
172
|
+
//# sourceMappingURL=m2mclient.js.map
|