@crowdin/app-project-module 0.29.0 → 0.29.2

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.
@@ -41,10 +41,10 @@ function handle() {
41
41
  const existing = yield storage.getStorage().getMetadata(id);
42
42
  try {
43
43
  if (!!existing) {
44
- yield storage.getStorage().updateMetadata(id, metadata);
44
+ yield storage.getStorage().updateMetadata(id, metadata, req.crowdinContext.crowdinId);
45
45
  }
46
46
  else {
47
- yield storage.getStorage().saveMetadata(id, metadata);
47
+ yield storage.getStorage().saveMetadata(id, metadata, req.crowdinContext.crowdinId);
48
48
  }
49
49
  }
50
50
  catch (e) {
package/out/index.js CHANGED
@@ -244,13 +244,13 @@ function addCrowdinEndpoints(app, clientConfig) {
244
244
  }
245
245
  return {
246
246
  getMetadata: storage.getStorage().getMetadata.bind(storage.getStorage()),
247
- saveMetadata: (id, metadata) => __awaiter(this, void 0, void 0, function* () {
247
+ saveMetadata: (id, metadata, crowdinId) => __awaiter(this, void 0, void 0, function* () {
248
248
  const existing = yield storage.getStorage().getMetadata(id);
249
249
  if (existing) {
250
- yield storage.getStorage().updateMetadata(id, metadata);
250
+ yield storage.getStorage().updateMetadata(id, metadata, crowdinId);
251
251
  }
252
252
  else {
253
- yield storage.getStorage().saveMetadata(id, metadata);
253
+ yield storage.getStorage().saveMetadata(id, metadata, crowdinId);
254
254
  }
255
255
  }),
256
256
  deleteMetadata: storage.getStorage().deleteMetadata.bind(storage.getStorage()),
@@ -260,7 +260,16 @@ function addCrowdinEndpoints(app, clientConfig) {
260
260
  return JSON.parse(integrationCredentials.config);
261
261
  }
262
262
  }),
263
- establishCrowdinConnection: (jwtToken) => (0, crowdin_client_1.prepareCrowdinRequest)(jwtToken, config),
263
+ establishCrowdinConnection: (authRequest) => {
264
+ let jwtToken = '';
265
+ if (typeof authRequest === 'string') {
266
+ jwtToken = authRequest;
267
+ }
268
+ else {
269
+ jwtToken = (0, crowdin_client_1.getToken)(authRequest);
270
+ }
271
+ return (0, crowdin_client_1.prepareCrowdinRequest)(jwtToken, config);
272
+ },
264
273
  encryptCrowdinConnection: (data) => (0, util_1.encryptData)(config, JSON.stringify(data)),
265
274
  dencryptCrowdinConnection: (hash) => __awaiter(this, void 0, void 0, function* () {
266
275
  const { crowdinId, extra } = JSON.parse((0, util_1.decryptData)(config, hash));
@@ -1,10 +1,11 @@
1
1
  /// <reference types="qs" />
2
2
  import Crowdin from '@crowdin/crowdin-api-client';
3
3
  import { Response } from 'express';
4
- import { Config, CrowdinContextInfo, SubscriptionInfo } from '../models';
4
+ import { Config, CrowdinClientRequest, CrowdinContextInfo, SubscriptionInfo } from '../models';
5
5
  export declare function prepareCrowdinRequest(jwtToken: string, config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): Promise<{
6
6
  context: CrowdinContextInfo;
7
7
  client?: Crowdin;
8
8
  subscriptionInfo?: SubscriptionInfo;
9
9
  }>;
10
10
  export default function handle(config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
11
+ export declare function getToken(req: CrowdinClientRequest): string | undefined;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.prepareCrowdinRequest = void 0;
12
+ exports.getToken = exports.prepareCrowdinRequest = void 0;
13
13
  const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
14
14
  const storage_1 = require("../storage");
15
15
  const util_1 = require("../util");
@@ -91,3 +91,4 @@ function getToken(req) {
91
91
  }
92
92
  }
93
93
  }
94
+ exports.getToken = getToken;
@@ -745,14 +745,14 @@ export declare enum ContextOptionsTypes {
745
745
  REDIRECT = "redirect"
746
746
  }
747
747
  export interface CrowdinAppUtilities {
748
- saveMetadata: (id: string, metadata: any) => Promise<void>;
748
+ saveMetadata: (id: string, metadata: any, crowdinId?: string) => Promise<void>;
749
749
  getMetadata: (id: string) => Promise<any | undefined>;
750
750
  deleteMetadata: (id: string) => Promise<void>;
751
751
  /**
752
752
  * Settings that users manage in the integration module
753
753
  */
754
754
  getUserSettings: (clientId: string) => Promise<any | undefined>;
755
- establishCrowdinConnection: (jwtToken: string) => Promise<{
755
+ establishCrowdinConnection: (authRequest: string | CrowdinClientRequest) => Promise<{
756
756
  context: CrowdinContextInfo;
757
757
  client?: Crowdin;
758
758
  }>;