@crowdin/app-project-module 0.98.0-cf-2 → 0.98.0-cf-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.
@@ -96,4 +96,9 @@ export declare class D1Storage implements Storage {
96
96
  saveSyncedData(files: any, integrationId: string, crowdinId: string, type: string): Promise<void>;
97
97
  updateSyncedData(files: any, integrationId: string, crowdinId: string, type: string): Promise<void>;
98
98
  getSyncedData(integrationId: string, crowdinId: string, type: string): Promise<IntegrationSyncedData | undefined>;
99
+ /**
100
+ * Converts undefined values to null for D1 compatibility
101
+ * D1 does not support undefined values, so we convert them to null
102
+ */
103
+ private sanitizeBindValues;
99
104
  }
package/out/storage/d1.js CHANGED
@@ -152,7 +152,7 @@ class D1Storage {
152
152
  return __awaiter(this, void 0, void 0, function* () {
153
153
  yield this.db
154
154
  .prepare('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
155
- .bind(credentials.id, credentials.appSecret, credentials.domain, credentials.userId, credentials.agentId, credentials.organizationId, credentials.baseUrl, credentials.accessToken, credentials.refreshToken, credentials.expire, credentials.type)
155
+ .bind(...this.sanitizeBindValues(credentials.id, credentials.appSecret, credentials.domain, credentials.userId, credentials.agentId, credentials.organizationId, credentials.baseUrl, credentials.accessToken, credentials.refreshToken, credentials.expire, credentials.type))
156
156
  .run();
157
157
  });
158
158
  }
@@ -160,7 +160,7 @@ class D1Storage {
160
160
  return __awaiter(this, void 0, void 0, function* () {
161
161
  yield this.db
162
162
  .prepare('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, agent_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?')
163
- .bind(credentials.appSecret, credentials.domain, credentials.userId, credentials.agentId, credentials.organizationId, credentials.baseUrl, credentials.accessToken, credentials.refreshToken, credentials.expire, credentials.id)
163
+ .bind(...this.sanitizeBindValues(credentials.appSecret, credentials.domain, credentials.userId, credentials.agentId, credentials.organizationId, credentials.baseUrl, credentials.accessToken, credentials.refreshToken, credentials.expire, credentials.id))
164
164
  .run();
165
165
  });
166
166
  }
@@ -438,7 +438,7 @@ class D1Storage {
438
438
  }
439
439
  const result = yield this.db
440
440
  .prepare(`SELECT id, action, message, data, created_at as createdAt, integration_id as integrationId, crowdin_id as crowdinId FROM user_errors WHERE crowdin_id = ? AND ${whereIntegrationCondition}`)
441
- .bind(...params)
441
+ .bind(...this.sanitizeBindValues(...params))
442
442
  .all();
443
443
  return result.results || [];
444
444
  });
@@ -447,7 +447,7 @@ class D1Storage {
447
447
  return __awaiter(this, void 0, void 0, function* () {
448
448
  yield this.db
449
449
  .prepare('INSERT INTO user_errors(action, message, data, created_at, integration_id, crowdin_id) VALUES (?, ?, ?, ?, ?, ?)')
450
- .bind(action, message, data, createdAt, integrationId, crowdinId)
450
+ .bind(...this.sanitizeBindValues(action, message, data, createdAt, integrationId, crowdinId))
451
451
  .run();
452
452
  });
453
453
  }
@@ -461,7 +461,7 @@ class D1Storage {
461
461
  }
462
462
  yield this.db
463
463
  .prepare(`DELETE FROM user_errors WHERE created_at < ? AND crowdin_id = ? AND ${whereIntegrationCondition}`)
464
- .bind(...params)
464
+ .bind(...this.sanitizeBindValues(...params))
465
465
  .run();
466
466
  });
467
467
  }
@@ -694,7 +694,7 @@ class D1Storage {
694
694
  const values = keys.map((key) => data[key]);
695
695
  yield this.db
696
696
  .prepare(`INSERT INTO ${tableName} (${columns}) VALUES (${placeholders})`)
697
- .bind(...values)
697
+ .bind(...this.sanitizeBindValues(...values))
698
698
  .run();
699
699
  });
700
700
  }
@@ -709,7 +709,7 @@ class D1Storage {
709
709
  const offsetClause = options.offset ? ` OFFSET ${options.offset}` : '';
710
710
  const query = `SELECT ${distinctKeyword}${columns} FROM ${tableName}${whereClause}${orderByClause}${limitClause}${offsetClause};`;
711
711
  const stmt = this.db.prepare(query);
712
- const result = params.length > 0 ? yield stmt.bind(...params).all() : yield stmt.all();
712
+ const result = params.length > 0 ? yield stmt.bind(...this.sanitizeBindValues(...params)).all() : yield stmt.all();
713
713
  return result.results || [];
714
714
  });
715
715
  }
@@ -722,7 +722,7 @@ class D1Storage {
722
722
  const query = `UPDATE ${tableName} SET ${setClause} ${whereClause};`;
723
723
  yield this.db
724
724
  .prepare(query)
725
- .bind(...values, ...params)
725
+ .bind(...this.sanitizeBindValues(...values, ...params))
726
726
  .run();
727
727
  });
728
728
  }
@@ -731,7 +731,7 @@ class D1Storage {
731
731
  const query = `DELETE FROM ${tableName} ${whereClause};`;
732
732
  const stmt = this.db.prepare(query);
733
733
  if (params.length > 0) {
734
- yield stmt.bind(...params).run();
734
+ yield stmt.bind(...this.sanitizeBindValues(...params)).run();
735
735
  }
736
736
  else {
737
737
  yield stmt.run();
@@ -765,5 +765,12 @@ class D1Storage {
765
765
  }
766
766
  });
767
767
  }
768
+ /**
769
+ * Converts undefined values to null for D1 compatibility
770
+ * D1 does not support undefined values, so we convert them to null
771
+ */
772
+ sanitizeBindValues(...values) {
773
+ return values.map((v) => (v === undefined ? null : v));
774
+ }
768
775
  }
769
776
  exports.D1Storage = D1Storage;
package/out/types.d.ts CHANGED
@@ -107,9 +107,9 @@ export interface ClientConfig extends ImagePath {
107
107
  */
108
108
  d1Config?: D1StorageConfig;
109
109
  /**
110
- * Cloudflare Workers Assets Fetcher
110
+ * Cloudflare Workers Assets configuration
111
111
  */
112
- assets?: Fetcher;
112
+ assetsConfig?: AssetsConfig;
113
113
  /**
114
114
  * integration module logic
115
115
  */
@@ -273,6 +273,12 @@ export interface ClientConfig extends ImagePath {
273
273
  */
274
274
  restrictAiToSameApp?: boolean;
275
275
  }
276
+ export interface AssetsConfig {
277
+ /**
278
+ * Cloudflare Workers Assets Fetcher
279
+ */
280
+ fetcher: Fetcher;
281
+ }
276
282
  export interface Environments {
277
283
  environments?: Environment | Environment[];
278
284
  }
@@ -48,8 +48,9 @@ function proxyAssetsResponse(fetcher, assetPath, baseUrl, req, res, next) {
48
48
  * @param staticPath - Path to static directory
49
49
  */
50
50
  function serveStatic(config, staticPath) {
51
- if (config.assets) {
52
- const assetsFetcher = config.assets;
51
+ var _a;
52
+ if ((_a = config.assetsConfig) === null || _a === void 0 ? void 0 : _a.fetcher) {
53
+ const assetsFetcher = config.assetsConfig.fetcher;
53
54
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
54
55
  const assetPath = staticPath.startsWith('/') ? `${staticPath}${req.path}` : `/${staticPath}${req.path}`;
55
56
  yield proxyAssetsResponse(assetsFetcher, assetPath, config.baseUrl, req, res, next);
@@ -66,8 +67,9 @@ exports.serveStatic = serveStatic;
66
67
  */
67
68
  function serveFile(config, filePath) {
68
69
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
69
- if (config.assets) {
70
- const assetsFetcher = config.assets;
70
+ var _a;
71
+ if ((_a = config.assetsConfig) === null || _a === void 0 ? void 0 : _a.fetcher) {
72
+ const assetsFetcher = config.assetsConfig.fetcher;
71
73
  const assetPath = filePath.startsWith('/') ? filePath : `/${filePath}`;
72
74
  yield proxyAssetsResponse(assetsFetcher, assetPath, config.baseUrl, req, res, next);
73
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.98.0-cf-2",
3
+ "version": "0.98.0-cf-4",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",