gas-drive 1.0.0 → 1.1.0

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 ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0
4
+ - Peer dependency on `gas-contract` bumped to `^0.2.0` (zod 4 migration upstream).
5
+ - zod 4 migration: enum messages now use the `error` option (zod 4 ignores `errorMap`), preserving Spanish messages.
6
+
7
+ ## 1.0.1
8
+ - Fix undefined `GD_CONFIG` / `GD_DRIVE_CONFIG` references: all reads go through `_obtenerConfigDrive()`.
9
+ - Config is read lazily from `GAS_MANIFEST.extensions.drive.manifest`, so `.gs` load order no longer matters.
10
+ - Fix false-green test T2.5: it now asserts the real contract instead of matching a stale comment.
11
+ - Peer dependency on `gas-contract` uses `^0.1.0` instead of a `file:` path.
12
+
13
+ ## 1.0.0
14
+ - Initial release: `gdSetup()`, `gdSubirArchivo()`, and the `gd_Drive.gs` runtime.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pedro Alejandro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Subida y gestión de archivos en Google Drive para `gas-contract`. Aporta runtim
6
6
 
7
7
  ## Peer dependency
8
8
 
9
- - `gas-contract@0.5.0` — contrato `GasExtension` con F1-F3 obligatorios.
9
+ - `gas-contract@^0.1.0` — contrato `GasExtension` y config-objeto de la familia.
10
10
 
11
11
  ## Instalación
12
12
 
@@ -17,7 +17,7 @@ npm install --save-dev gas-drive
17
17
  ## Contrato `GasExtension` — factory `drive()`
18
18
 
19
19
  ```js
20
- import drive from 'gas-drive';
20
+ import { drive } from 'gas-drive';
21
21
 
22
22
  export default defineGasConfig({
23
23
  /* ...config del base... */
@@ -45,6 +45,10 @@ Todos los campos tienen default razonable: `drive({})` es válido.
45
45
 
46
46
  ## Runtime de GAS: `gd_Drive.gs`
47
47
 
48
+ > **Config:** el runtime lee su configuración desde `GAS_MANIFEST.extensions.drive.manifest`
49
+ > (inyectada por el build). El orquestador debe generar `Manifest.gs` —
50
+ > `angular-to-appsscript` (≥ 0.1.2) y `astro-to-appsscript` ya lo hacen.
51
+
48
52
  El build inyecta `runtime/gd_Drive.gs` en `dist-gas/`. Contiene dos funciones públicas:
49
53
 
50
54
  - **`gdSetup(ctx)`** — setup idempotente: crea la carpeta si no existe, guarda su ID en `GD_MEDIA_FOLDER_ID`, la reusa si ya existe.
@@ -106,6 +110,51 @@ El cliente valida en el navegador con los MISMOS mensajes que el runtime de GAS:
106
110
  - MIME no permitido → error con el MIME recibido y los permitidos
107
111
  - Tamaño excedido → error con el límite y el tamaño actual
108
112
 
113
+ ## Pasos secuenciales
114
+
115
+ ```bash
116
+ # 1. Instalar (junto a su peer)
117
+ npm install --save-dev gas-drive gas-contract
118
+
119
+ # 2. Declararlo en gas.config.mjs
120
+ # 3. Compilar
121
+ npm run gas:build # = ng build && gas build && gas domain
122
+
123
+ # 4. Verificar
124
+ npm run gas:check
125
+
126
+ # 5. Subir
127
+ clasp push gas/
128
+ ```
129
+
130
+ ## Cómo se comunica con el resto
131
+
132
+ ```
133
+ gas.config.mjs ──extensions[]──► angular-to-appsscript (orquestador)
134
+ │
135
+ inyecta runtime/gd_Drive.gs en gas/
136
+ inyecta config → GAS_MANIFEST.extensions
137
+ │
138
+ ▼
139
+ Apps Script (scope global)
140
+ │
141
+ ▼
142
+ gdSetup, gdSubirArchivo
143
+ ```
144
+
145
+ | Vía | Qué viaja |
146
+ |---|---|
147
+ | `extensions[]` en tu config | `drive({ folder: "Media", allowedMimes: [...], maxBytes: 8*1024*1024 })` |
148
+ | `runtime/*.gs` (lo inyecta el build) | `gd_Drive.gs` con `gdSetup, gdSubirArchivo` |
149
+ | `GAS_MANIFEST.extensions.drive.manifest` | tu config, para que otros la lean |
150
+
151
+ **Las capacidades NO se importan entre sí.** Se leen por el manifest (R7):
152
+
153
+ ```js
154
+ const cfg = GAS_MANIFEST.extensions.drive?.manifest;
155
+ if (!cfg) return { ok: false, error: 'gas-drive no está instalado' };
156
+ ```
157
+
109
158
  ## Composición con otros paquetes
110
159
 
111
160
  Los paquetes de extensión no se importan entre sí. Se leen entre sí vía `GAS_MANIFEST.extensions.<nombre>.manifest` (inyectado por el base).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gas-drive",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Capa de archivos en Google Drive para la familia gas-* (Google Apps Script).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,13 +10,15 @@
10
10
  "index.mjs",
11
11
  "src/",
12
12
  "runtime/",
13
- "README.md"
13
+ "README.md",
14
+ "LICENSE",
15
+ "CHANGELOG.md"
14
16
  ],
15
17
  "engines": {
16
18
  "node": ">=20"
17
19
  },
18
20
  "peerDependencies": {
19
- "gas-contract": "^0.1.0"
21
+ "gas-contract": "^0.2.0"
20
22
  },
21
23
  "scripts": {
22
24
  "test": "node --test 'test/**/*.test.mjs'"
@@ -3,16 +3,39 @@
3
3
  // ES2019 plano, sin import/export.
4
4
  // Funciones públicas (sin _ al inicio ni al final): gdSetup, gdSubirArchivo.
5
5
  // Funciones privadas (empiezan con _): _*.
6
- // Toda la configuración llega desde GD_CONFIG (inyectada por el build desde
7
- // manifest.extensions.drive.manifest).
8
-
9
- var GD_DRIVE_CONFIG = {
10
- folder: 'Media',
11
- allowedMimes: ['image/jpeg', 'image/png', 'image/webp', 'image/gif'],
12
- maxBytes: 8 * 1024 * 1024,
13
- sharing: 'ANYONE_WITH_LINK',
14
- imageUrlMode: 'direct',
15
- };
6
+ // Toda la configuración llega desde GAS_MANIFEST.extensions.drive.manifest
7
+ // (inyectada por el build). Si no está disponible, se usan defaults razonables.
8
+ function _obtenerConfigDrive() {
9
+ try {
10
+ if (
11
+ typeof GAS_MANIFEST !== 'undefined' &&
12
+ GAS_MANIFEST &&
13
+ GAS_MANIFEST.extensions &&
14
+ GAS_MANIFEST.extensions.drive
15
+ ) {
16
+ var bloque = GAS_MANIFEST.extensions.drive;
17
+ var m = bloque.manifest ? bloque.manifest : bloque;
18
+ if (m) {
19
+ return {
20
+ folder: m.folder || 'Media',
21
+ allowedMimes: m.allowedMimes || ['image/jpeg', 'image/png', 'image/webp', 'image/gif'],
22
+ maxBytes: m.maxBytes || 8 * 1024 * 1024,
23
+ sharing: m.sharing || 'ANYONE_WITH_LINK',
24
+ imageUrlMode: m.imageUrlMode || 'direct',
25
+ };
26
+ }
27
+ }
28
+ } catch (e) {
29
+ // fall through to default
30
+ }
31
+ return {
32
+ folder: 'Media',
33
+ allowedMimes: ['image/jpeg', 'image/png', 'image/webp', 'image/gif'],
34
+ maxBytes: 8 * 1024 * 1024,
35
+ sharing: 'ANYONE_WITH_LINK',
36
+ imageUrlMode: 'direct',
37
+ };
38
+ }
16
39
 
17
40
  var GD_PROP_ID = 'GD_MEDIA_FOLDER_ID';
18
41
 
@@ -90,7 +113,7 @@ function gdSetup(ctx) {
90
113
  }
91
114
 
92
115
  if (!carpeta) {
93
- carpeta = _obtenerOCrearCarpeta(GD_CONFIG.folder);
116
+ carpeta = _obtenerOCrearCarpeta(_obtenerConfigDrive().folder);
94
117
  creado = true;
95
118
  if (propiedades.setProperty) {
96
119
  propiedades.setProperty(GD_PROP_ID, carpeta.getId());
@@ -98,12 +121,12 @@ function gdSetup(ctx) {
98
121
  }
99
122
 
100
123
  var reporte = {
101
- created: creado ? [GD_CONFIG.folder] : [],
102
- reused: creado ? [] : [GD_CONFIG.folder],
124
+ created: creado ? [_obtenerConfigDrive().folder] : [],
125
+ reused: creado ? [] : [_obtenerConfigDrive().folder],
103
126
  };
104
127
 
105
128
  if (ctx && ctx.log) {
106
- ctx.log('gdSetup: carpeta ' + GD_CONFIG.folder + ' ' + (creado ? 'creada' : 'reusada'));
129
+ ctx.log('gdSetup: carpeta ' + _obtenerConfigDrive().folder + ' ' + (creado ? 'creada' : 'reusada'));
107
130
  }
108
131
 
109
132
  return reporte;
@@ -116,27 +139,27 @@ function gdSubirArchivo(parametros) {
116
139
  var base64 = parametros && parametros.base64 ? parametros.base64 : '';
117
140
 
118
141
  // Validar MIME
119
- if (!_validarMime(mimeType, GD_DRIVE_CONFIG)) {
142
+ if (!_validarMime(mimeType, _obtenerConfigDrive())) {
120
143
  return {
121
144
  ok: false,
122
- error: 'MIME no permitido: ' + mimeType + '. Permitidos: ' + GD_DRIVE_CONFIG.allowedMimes.join(', '),
145
+ error: 'MIME no permitido: ' + mimeType + '. Permitidos: ' + _obtenerConfigDrive().allowedMimes.join(', '),
123
146
  };
124
147
  }
125
148
 
126
149
  // Validar tamaño
127
150
  var bytes = base64 ? Math.ceil((base64.length * 3) / 4) : 0;
128
- if (!_validarTamaño(bytes, GD_DRIVE_CONFIG)) {
151
+ if (!_validarTamaño(bytes, _obtenerConfigDrive())) {
129
152
  return {
130
153
  ok: false,
131
- error: 'Tamaño excede el límite (' + GD_DRIVE_CONFIG.maxBytes + ' bytes): ' + bytes + ' bytes',
154
+ error: 'Tamaño excede el límite (' + _obtenerConfigDrive().maxBytes + ' bytes): ' + bytes + ' bytes',
132
155
  };
133
156
  }
134
157
 
135
158
  // Saneado de nombre
136
- var nombreArchivo = _saneadoNombre(nombre, GD_CONFIG);
159
+ var nombreArchivo = _saneadoNombre(nombre, _obtenerConfigDrive());
137
160
 
138
161
  // Obtener o crear carpeta
139
- var carpeta = _obtenerOCrearCarpeta(GD_CONFIG.folder);
162
+ var carpeta = _obtenerOCrearCarpeta(_obtenerConfigDrive().folder);
140
163
 
141
164
  // Crear archivo
142
165
  var bytesArray = Utilities.base64Decode(base64);
@@ -144,7 +167,7 @@ function gdSubirArchivo(parametros) {
144
167
  var archivo = carpeta.createFile(blob);
145
168
 
146
169
  // Aplicar sharing
147
- var sharingAplicado = _aplicarSharing(archivo, GD_DRIVE_CONFIG.sharing);
170
+ var sharingAplicado = _aplicarSharing(archivo, _obtenerConfigDrive().sharing);
148
171
 
149
172
  var resultado = {
150
173
  ok: true,
@@ -153,7 +176,7 @@ function gdSubirArchivo(parametros) {
153
176
  mimeType: archivo.getMimeType(),
154
177
  sizeBytes: archivo.getSize(),
155
178
  driveUrl: _urlDrive(archivo.getId()),
156
- imageUrl: _urlImagen(archivo.getId(), GD_DRIVE_CONFIG.imageUrlMode),
179
+ imageUrl: _urlImagen(archivo.getId(), _obtenerConfigDrive().imageUrlMode),
157
180
  sharingApplied: sharingAplicado,
158
181
  };
159
182
 
package/src/schema.mjs CHANGED
@@ -22,16 +22,12 @@ export const driveConfigSchema = z
22
22
  .default(8 * 1024 * 1024),
23
23
  sharing: z
24
24
  .enum(['ANYONE_WITH_LINK', 'PRIVATE'], {
25
- errorMap: () => ({
26
- message: "sharing debe ser 'ANYONE_WITH_LINK' o 'PRIVATE'",
27
- }),
25
+ error: "sharing debe ser 'ANYONE_WITH_LINK' o 'PRIVATE'",
28
26
  })
29
27
  .default('ANYONE_WITH_LINK'),
30
28
  imageUrlMode: z
31
29
  .enum(['direct', 'thumbnail'], {
32
- errorMap: () => ({
33
- message: "imageUrlMode debe ser 'direct' o 'thumbnail'",
34
- }),
30
+ error: "imageUrlMode debe ser 'direct' o 'thumbnail'",
35
31
  })
36
32
  .default('direct'),
37
33
  })